Hello dear community,
I would like to create Script Validator [ScriptRunner]' Validator for "Create" transition that will check the value filled in a custom filed "Other Devices" which is LABEL custom field, when creating a new ticket.
I have used a regular expression but it seems not working:
I have tested using this code:
cfValues["Other Devices"] == "D1|E2|V2H|H2|M2|M2-N|D3|E3|H3|H3-N|M3-W|M3-N|V3M|V3H|V3U|V4M|S4|V4H|Other|P926x"
It didn't work then I tried : cfValues["Other Devices"] == 'D1' and didn't work too.
I would like that my custom field accepts only this values: D1|E2|V2H|H2|M2|M2-N|D3|E3|H3|H3-N|M3-W|M3-N|V3M|V3H|V3U|V4M|S4|V4H|Other|P926x
Please, could you help me on this issue?
Best regards,
Hi @Vincent Leduby Try below Code, it should work :-
Apply this is Simple Scripted Validator
cfValues['Other Devices'] ==~ /^(D1|E2|V2H|H2|M2|M2-N|D3|E3|H3|H3-N|M3-W|M3-N|V3M|V3H|V3U|V4M|S4|V4H|Other|P926x)*$/
Let me know the result
Thanks
Vikrant Yadav
Hello @Vikrant Yadav
Thank you for your help.
After adding your script, I did a test by adding D1 value to the custom field "Other devices" but the error message is shown.
I have added some screenshots to my answer.
Thank you again for help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vincent Leduby Little change in script,
Tested on my side, it's working fine. Give it a try.
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.label.Label
def customFieldManager = ComponentAccessor.getCustomFieldManager()
int otherdevicesId = 35851 //replace with custom field id
def other_devicesField = customFieldManager.getCustomFieldObject(otherdevicesId)
def devicesFieldValue = issue.getCustomFieldValue(other_devicesField)
devicesFieldValue.each { label ->
if (!label.toString().matches("(D1|E2|V2H|H2|M2|M2-N|D3|E3|H3|H3-N|M3-W|M3-N|V3M|V3H|V3U|V4M|S4|V4H|Other|P926x)")){
throw new InvalidInputException( "Kindly use correct value")
}
}
Let me know the result. Hope it works for you!
Thanks
Vikrant Yadav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Vikrant Yadav ,
Thank you very very much for your help.
It works like a charm.
I really appreciate your help!
Best regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great :)
Glad to hear it works for you!
Kindly accept the answer if solution works for you so that it helps others users having same query.
Stay Safe!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.