Validate checkbox custom field with Scriptrunner

Danish Hussain Sabunwala May 20, 2021

Hi Team,

Forgive me if it comes up as a silly question since I am a complete beginner to Scriptrunner. I am trying to add the following validator script to Workflow but getting the following error.

cfValues['Sub-Status']*.value.contains("On hold")

Here 'Sub-Status' is a checkbox field having only 1 value 'On hold' currently.

Error Validator.PNG

Could you please help me with the solution?

Thanks and Regards

Danish Hussain

 

2 answers

1 accepted

3 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 20, 2021

Hi Danish,

Thank you for your question.

I can confirm that the reason for your error is due to your validator expression is not valid code for Jira cloud and is groovy code that will only work on Jira server.

I can confirm that inside of Jira Cloud that validators are designed using the Jira Expression Framework and you would need to use this expression syntax to define the validator that you require.

I can confirm that we have a knowledge base article located here which explains how you can use this to create the validator that you want with ScriptRunner for Jira Cloud and I hope this helps to achieve your requirement.

I hope this information helps.

Regards,

Kristian

Danish Hussain Sabunwala May 20, 2021

Hello @Kristian Walker _Adaptavist_ ,
Thank you for the above links.

I was able to find scripts related to labels, links, discription, sub-tasks etc. but unable to get anything regarding Checkboxes.

If possible, could you provide a code similar to cfValues['Sub-Status']*.value.contains("On hold") for JIRA cloud?

 

Thanks in advance,

Danish Hussain Sabunwala

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 20, 2021

Hi Danish,

I have added an example here on line 55 which shows gow to validate that a checkbox field must contain just a single value.

Please note if you need to change this example you will be able to modify this using the Jira Expression framework doucmentation as an example to help you to modify it using the Jira Expression framework doucmentation as a guide to help you to achieve this.

I hope this helps.

Regards,

Kristian

Danish Hussain Sabunwala May 20, 2021

Hello @Kristian Walker _Adaptavist_ ,

Thanks a lot for your help. The following code provided the answer I was looking for.

Regards,

Danish Hussain Sabunwala 

0 votes
Guilhem Dupuy
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 20, 2021

Hello @Danish Hussain Sabunwala ,

I'm no Scriptrunner expert either, but I think you can achieve what you want without using it !

You could use a simpler validator in your Jira Workflow called "Regular Expression Check". There, you simply have to select your Checkbox field, and enter the correct value the field must have to validate the transition.

 

Let me know if it helps,

Guilhem

Danish Hussain Sabunwala May 20, 2021

Hello @Guilhem Dupuy ,
If I use 'Regular Expression Check' then I won't be able to provide a custom Validator error message which is also a requirement from the user.

Is there any other approach, please do let me know?

Thanks and regards,

Danish Hussain

Guilhem Dupuy
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 20, 2021

Oh, I see why you were using Scriptrunner then.

Well as far as I'm aware there is no other way to do it, maybe you can manage to display an error message using Scriptrunner ?

Danish Hussain Sabunwala May 20, 2021

@Guilhem Dupuy , Yes it will be possible by using Scriptrunner Validators. But still not able to understand the above error. 

Guilhem Dupuy
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 20, 2021

@Danish Hussain Sabunwala as I said I'm no Scriptrunner expert I can't really help you with the code unfortunately I was just proposing a work-around :/ 

The column 24 seems to point to the "." character, but I don't understand why either :/ 

Danish Hussain Sabunwala May 20, 2021

@Guilhem Dupuy ,

Thank you for your time and response.
It is appreciated a lot.

Like Guilhem Dupuy likes this
Guilhem Dupuy
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 20, 2021

Thanks mate ! I hope you'll find an answer to your mater.

Suggest an answer

Log in or Sign up to answer