Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

scriptrunner validator to check if that at least one of 3 custom field is filled

Hi guys,

I need a Validator to check if an issue is created with at least 1 of 3 customfield filled.

This is what I write:

issue.customfield_10046!= null || issue.customfield_10045!= null || issue.customfield_10059!= null 

 

But in this way if I don't pass the first customfield(10046) but I pass one of the other 2(10045 or 10059) the validator stop me.

 

The strange things is that if I create che issue with an Rest API call, the validator stop me and I can't create the Issue   but if I  create the same Issue manually from Jira, the Validator didn't stop me. I don't know if this is because from Jira if a leave a Customfield empty is different if from a Rest Api I don't pass the customfield at all.

 

My answer is: there is a way to write something like that: 

issue.customfield_10046!= null || issue.customfield_10045!= null || issue.customfield_10059!= null 

 

that works  always from Jira and  From rest api call?

 

P.S: I have Jira premium

 

Thanks

2 answers

Hi Ricardo,

Thank you for your question.

I can confirm that Workflow Validators are defined using the Jira Expression Framework as documented in the Atlassian API documentation page located here or in the documentation page located here which explains how to add in a new validator to your workflow.

I can confirm that when viewing the Jira Expression Framework API documentation page linked above you can navigate to the Context variables section which shows what variables are provided by this framework that can be used to create the expression.

If you then click on one of the variables it will show all the properties that can be called on the variable for the expression such as for the issue variable as shown here and you will be able to check this to see if Atlassian provides a variable that can be checked against to help create the validator which you require.

I am unable to provide an exact expression to achieve your requirement, but you can use the resources shared above as a reference guide to help create that validator expression which you require.

Finally, so that I can advise further can I please ask what types are each of your custom fields so that I can advise further on how to achieve this requirement and how you can check these field values.

Regards,

Kristian

Hi  Kristian,

Thank you but i have read the documentation and i'm sure that in the validator I can do this: issue.customfield_10046  and I am sure that i can receive the value of the field, the problem is when I mix 2 condition and not only 1, it is like that the validator don't see the second condition but it stop to the first, can you confirm that the scripturnner validator see only first condition and not the second one?

I need to check if at least 1 of 3 customfield is not empty

 

Thanks

Hi Ricardo,

I can confirm that it is possible with *ScriptRunner for Jira Cloud* to check more than one field as we just use the *Jira Expression* framework that Atlassian provides to run expressions.

If you are able to confirm for me what type each custom field you are using is then I will be able to check in my local cloud instance, in order to advise further on how you could look to achieve your requirement.

Regards,

Kristian

Hi kristian,

the customfield_10046 and customfield_10045 are label type, the customfield_10059 is a text(multi line).

and this is my expression that doesen't work by Rest API call: 

issue.customfield_10046!= null || issue.customfield_10045!= null || issue.customfield_10059!= null 

 

My need is:

check that at least one of the 3 customfields is not empty

 

Thanks

Hi Ricardo,

I have just done a test using two labels fields and a multi-line text field and can confirm that your expression is valid and can confirm that If you configure a script runner validator using this with the expression defined on a single line then it works.

When I create a new issue to run the create transition in the workflow on an issue with this expression if none of the three fields has a value I get the error message defined and cannot create the issue and if one of the fields has a value then I can execute the transition and create the issue.

Can you please provide a screenshot or screen recording showing how you are running your expression and when you are getting the error?

Regards,

Kristian

Hi Ricardo,

I have also done a test creating a new issue from the Script Console and can confirm that if when creating an issue that you do not specify a value for one of the fields in the validator in the body of the request to create the issue that the validator will fail and the issue will not be created.

This is how Jira is designed and the Atlassian Rest API's which Jira uses mandate that the validators must pass for the issue to be created as the API's use the same rules as defined in the create transition for the workflow.

This means that you cannot skip this validator logic or override it when creating an issue via a Rest API call as Atlassian does not permit this and this means you must specify the value for one of the fields in the body of the request to create the issue.

I hope this helps,

Regards,

Kristian

Hi Kristian,

I don't want to skip che validator from the rest API, the opposite, I want that the validator is valid everywhere.

In the first pic there is the validator (issue.customfield_10046!= null || issue.customfield_10045!= null || issue.customfield_10059!= null )

In the second pic there is the Rest API call, I have passed only the customfield 10059 and not the 10046 and 10045 and the Validator stop me, and Appear the error message

In the third pic you can see the validator log, that say that the customfield 10046 is necessary. But like you can see in the first pic I want only 1 of the 3.

 

I have noted that the required field is the first writed in the validator, if I change the order and I set the customfield_10045 in the first position of the validator, the error is that customfield_10045 is necessary, is like if the validator only see the first condition

validator.PNGmoba_n.jpgvalidatoErrore.PNG

Hi Ricardo,

Can you please edit your validator expression as it looks as if you have a cartridge return line feed at the end of the expression which is causing the validator to fail.

I have checked the logic of your validator in my local instance and can confirm that this valid and that it will work both in a workflow validator and when creating an issue from the rest API so this indicates that there must either be some invalid characters in your validator or the ID of one of the fields you have specified is not correct.

Also, can you please double-check what the ID of the fields is as this error may occur if one of the fields you have specified is incorrect?

Regards,

Kristian

Hi Kristian,

I am sure about that the ID of the fields are correct and I have also edited the validator and i have removed all the blank line or other things, now i have only che character of the validator but it doesen't work anyway.

If i change the id in the validator, it always says that the validator is incorrect and i always have the same error message, that the first customfield i have write in the validator is missed. It is like the validator only take care of the first expression, and it doesen't see the "OR" expression I have used 

 

I don't know what other things control. I Need this validator for my project

Hi Ricardo,

Can I please ask you to remove the validator and to recreate as I like I have said I have tested your validator and it works as expected in my instance and checks all three fields so this must be caused some configuration in your instance and I cannot advise further on this as I have validated this and proved your expression works correctly inside of my instance. 

Regards,

Kristian

Hi Ricardo,

I have just checked again and can confirm this error message you are getting is the correct message that will be shown when one value is not specified and that validators only show the history for when an execution fails due to how they have been defined.

This means if you save the validator and create an issue ensuring a value is filled in on one of the three fields then the validator will allow the issue to be created and to work as expected.

I hope this helps.

Regards,

Kristian

Hi Kristian,

can you share me the screenshot of your rest API call?  because I think the problem is: if don't write the customfield in the API, the value that validator receives is not null but other value

Hi Ricardo,

Can I please ask are you asking for a screenshot of the script I ran from the script console or the script from the expression specified in the workflow validator?

Regards,

Kristian

Hi Kristian,

the screen of the script in your script console

 

Thanks

Hi Ricardo,

I can confirm to see the rest call and the screen I used you will need to go to the script Console page in your instance at the URL of <JiraCloudURL>/plugins/servlet/ac/com.onresolve.jira.groovy.groovyrunner/script-console?s=com.onresolve.jira.groovy.groovyrunner__script-console and then clicking on the link named Create Task in the Examples section below the code box as this will populate with the script that contains the rest call that I used.

Regards,

Kristian

Hi @Riccardo Micozzi unfortunately I don't have a solution for this. I'm experiencing somethign similar that I cannot validate custom fields during create transitions, but only when the isse is already created and the transition isn't 'create'. Did you find out something in the end?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you