customefield type Label : Length of each entered input into the field should be 8

Anupam Sinha June 10, 2021

Hello Community

 

I am stuck with a scenario. Please help me. I have a custom field type : Label in my issuetype Epic. Name of Label (customefield is) :  Additional IDs.

Scenario

User is expected to enter minimum 1 and maximum 10 Ids into the field and each entered Id must be 8 Characters long only. If user enters more than 10 Ids, an error should be shown on the screen. If user enter an Id which is not equal to 8 characters should throw an error on the screen as user updates epic.  

I have Scriptrunner installed on my jira server edition. 

Please advice me how to implement this constraints on the field. 

Thank you .

Anupam

1 answer

0 votes
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 11, 2021

You can add a Validator of type Simple scripted validator [ScriptRunner] with a Condition like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.CustomField
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField myCustomField = customFieldManager.getCustomFieldObjectsByName("Your Custom Field Name")[0]
boolean allValidLength = true
int numLabels = 0
issue.getCustomFieldValue(myCustomField).each{
numLabels++
if(it.toString().size() != 8){
allValidLength = false
}
}
return numLabels <= 10 && allValidLength

And an Error Message like: Each Additional ID must be 8 characters in length, and there must not be more than 10 of them.

Anupam Sinha June 14, 2021

Thanks for replying and help @Payne

I am not sure at which status I should add this validator. I have large workflow with more than 10 statuses. User wants check should be in place at screen and irrespective of status of Epic. 

 

Thanks,

Anupam 

Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2021

In a situation like this we have put a validator near the beginning of the workflow when the issue is created and one more near closure. Think about when the user will provide those IDs and go from there.

Suggest an answer

Log in or Sign up to answer