Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Does Jira Scriptrunner's behaviours gets applied when someone comes through REST API instead of UI

Nikhil Tyagi May 9, 2020

So i created a Scriptrunner Behaviour to add some servor side validations on a custom field. It works fine someone is editing the field through UI. But at the same time when someone edits the field using the Jira REST API, the validations aren't applied. 

 

Do i need to add something else to make it work? Please suggest.

Here is my code snap: 

 

def fieldToHide = getFieldByName("abc")
def urgencia = getFieldByName("def")
def optionValue = urgencia.getValue().toString()

fieldToHide.setHidden(true)

 

if (optionValue == 'xxx') {
urgencia.setError("You cannot enter xxx")
}

else {

fieldToHide.setHidden(false)

}

1 answer

0 votes
Nic Brough -Adaptavist-
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.
May 9, 2020

No, because Behaviours are mostly done by adding scripts to the page so the browser does the work as it renders the page.  REST renders nothing, there's nowhere to run the Behaviour.

Nikhil Tyagi May 9, 2020

Hey, Thanks for your prompt reply. Is there a way we can achieve the same behaviour for REST calls as well as it would be more consistent?

Nic Brough -Adaptavist-
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.
May 9, 2020

Not for edit actions.  Best you can do is put validators on transitions so issues cannot progress with invalid data.

Nikhil Tyagi May 9, 2020

True but validators are attached to certain Workflows right? My requirement is attach it to an Issue type. Is that possible? 

 

For eg: i want to attach validations for few custom fields for an issue type 'ABC' whenever someone creates/edits. 

Nic Brough -Adaptavist-
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.
May 10, 2020

You cannot attach any validation to an issue type.  You attach validation to a workflow.  You attach Behaviours to screens (but REST has not got any).

You will need to put validators on the create transition for REST creates to be checked.  Edit has no validation beyond what each field can do.

Nikhil Tyagi May 10, 2020

Ok that makes sense. So how do you suggest i approach this problem given that my issue type maybe be attached to multiple workflows and

1. whenever someone creates/edits an issue, i need to validate few custom fields and only if they are valid he/she should be able to submit the issue.

2. Also when someone edits the issue i want to enable few custom fields for edit based on a condition.

 

These two things should be applied irrespective of whether the user comes from UI or through REST API. 

 

Again i would like to thank you for your prompt and to-the point replies which really helped me and saved my time. Cheers!

Nic Brough -Adaptavist-
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.
May 10, 2020

You are not going to be able to validate Edit actions over REST, best you can do, as I said, is to prevent issues that have had invalid data set from progressing further through the workflow until corrected.

You can validate fields on create issue, add validators to the create transition.

There are no conditional edits in Jira, you can either edit a field or you can't, based on whether the field is on screen or not.

Suggest an answer

Log in or Sign up to answer