Script Runner Fast-track post function

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 26, 2023

Hello All,

Currently, I am using the below condition to transition the issue to next status but the field which we have is a multi-select field. 

cfValues['Enterprise Software']*.value != 'Other Software'
So if the users are selecting Another Value along with the 'Other Software' then the post function still triggers.
We want to modify the condition something like this>
cfValues['Enterprise Software']*.value contains none of 'Other Software'

So, if we select two values in the multi-select field like-

Value in (Other Software, New Software) then condition should be false.

If value = Other Software then False

Else True

1 answer

1 accepted

1 vote
Answer accepted
Bobby Bailey
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.
October 26, 2023

Hi @Manoj Gangwar , 

Your query should be:

'Other Software' !in cfValues['Enterprise Software']*.value

Could you give this a go and let me know how you get on?

Kind regards, 

Bobby

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 27, 2023

Its showing an error for !

Capture.PNG

Bobby Bailey
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.
October 27, 2023

This must be because you are on a fairly older version of ScriptRunner. The !in operator was added as part of the Groovy upgrade with release v7 of ScriptRunner:

https://docs.adaptavist.com/sr4js/latest/release-notes/release-7-x#groovy-3-update

With an older version of ScriptRunner, you can instead use this query:

!(cfValues['Enterprise Software']*.value).contains('Other Software')


However, I would always recommend looking to upgrade ScriptRunner when you can, there are a significant amount of upgrades for you to be able to take advantage of, one of the most significant being HAPI:

https://www.scriptrunnerhq.com/hapi

Kind regards, 

Bobby

Like Manoj Gangwar likes this
Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 27, 2023

Thanks for the quick resolution. We have a planned upgrade of Jira and Plugins.

It works now as expected. 

One more thing I want to run this Post function as a User = 'JSM User' but currently its running as a Default user and there is no option to change in in UI. Could you please suggest the script?

Bobby Bailey
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.
October 27, 2023

Currently using the Built-in Fast track Post Function there is no way for you to define the user who performs this action. 

Instead, what you would have to do it write a custom scripted Post Function. Is this script you can perform the same action (check the custom field doesn't include Other Software, and if it doesn't, transition the issue to another status) however, as you are writing a custom script using the Java API, you should be able to change the user who performs this action in the code. 

Your feedback is really useful though, and I will be sure to get this back to the product team. 

Thank you!

Bobby

Like # people like this
Stefan Stadler
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.
February 8, 2024

Hi @robert 

you mention that you can transition the issue in the custom script post-function.

Can you please let me know some example on how to do that?

When I try to do that in a listener, if is often resulting in some kind of a race condition (status changed according to the logs, but status value is still the old value).

Is this different in post-functions? And if so, do you know, why this is the case?

Thanks!

Bobby Bailey
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.
February 8, 2024

Hi @Stefan Stadler , 

 

Sure! You can find an example of how to transition an Issue in ScriptRunner for Jira Cloud here!


As for the issue you are facing, I am not 100% sure on the cause for that, as I don't have a full understanding of the chain of events from the Jira side. It could be the case that when you transition an issue, the event is fired to ScriptRunner and the Listener executes, but if you have a large number of post functions it could delay the update of the transition on the Jira side? But honestly I am guessing. 

However, having the script execute as a post function (and thus part of the transition) should solve this issue. 

Thanks, 

Bobby

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events