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

ScriptRunner help please

Zaldy Parian
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.
November 19, 2023

Hi all,

I got a business requirement to automatically assign values to 2 custom fields based on the selected values of a cascading field.  I tried Jira automation rule, but it has a limit of 65 conditions per rule. 

I'm exploring ScriptRunner Listener as an alternative. Can you please guide me how to write the groovy script? I've search the ScriptRunner library and nothing seems to address my requirements. I also gathered that I should be using "switch > case" statement for groovy script. 

A sub-set of the Jira automation is below (the sample below is not the full list of conditions)

project = "Sigma SDM " AND issuetype in (Incident, "Service Request with Approvals", Problem) AND
"Issue category" in cascadeOption ("Application (Non-SAP)", "MedAdvisor") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Fred") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "HealthEngine") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "KIA") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "LAMLab") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Last Yard") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "LOTS") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "MINFOS") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Navision") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Plexus") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "RPM") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Snap'n'Share") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Z") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Blueprint") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Corum") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "JDA") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Qualtrics") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "SpaceMan") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "Wageloch") OR
"Issue category" in cascadeOption ("Application (Non-SAP)", "eCommerce AMCAL/DDS")
- Functional area: Commercial / Resolver group: IT Commercial

project = "Sigma SDM " AND issuetype in (Incident, "Service Request with Approvals", Problem) AND
"Issue category" in cascadeOption ("Application (Non-SAP)", "Salesforce")
- Functional area: Commercial / Resolver group: IT Salesforce

project = "Sigma SDM " AND issuetype in (Incident, "Service Request with Approvals", Problem) AND
"Issue category" in cascadeOption ("Application (SAP)", "Concur")
- Functional area: Corporate / Resolver group: SAP Concur

project = "Sigma SDM " AND issuetype in (Incident, "Service Request with Approvals", Problem) AND
"Issue category" in cascadeOption ("Application (SAP)", "OpenText") OR
"Issue category" in cascadeOption ("Application (SAP)", "FICO") OR
"Issue category" in cascadeOption ("Application (SAP)", "Finance Supply") OR
"Issue category" in cascadeOption ("Application (SAP)", "Finance Tech")
- Functional area: Corporate / Resolver group: SAP Finance Management

 

Thanks,

 

2 answers

0 votes
Sean Chua _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.
November 21, 2023

Hey @Zaldy Parian , Good to see you here on Community. There is a new ScriptRunner for Jira Cloud Get Started Page which was just added. Not sure if the watch on demand "introduction to groovy " would help you there.

It would work alot better using Behaviours but it is unfortunate that it isn't available for JSM Cloud yet. Nevertheless, it is possible to use ScriptRunner's Listener to trigger when issue is created/updated.

You can also add in some Jira Expressions for some specific conditions to meet before it gets triggered if there are a few listeners running and you'd want to be specific about it. So do test before running it in your prod :)

I'm using a specific customfield name and it would look something like >> this <<, but you may need to adapt it to your instance. 

Hope this helps! 

0 votes
Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 19, 2023

Hi @Zaldy Parian,

can you share a bit more details about your requirement? You wrote:

I got a business requirement to automatically assign values to 2 custom fields based on the selected values of a cascading field.  I tried Jira automation rule, but it has a limit of 65 conditions per rule. 

Are the JQL statements you've specified the 65 conditions when you want to set these two fields? How about splitting your rule into multiple ones?

PS: You might want to remove/blank out some company names from your JQL statements to not reveal too much information.

Zaldy Parian
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.
November 20, 2023

Hi @Matthias Gaiser _K15t_ 

The requirement is something like...

If the issue category is = Application (Non SAP), and sub-category is = Salesforce;

then Functional area should be = Commercial, and

Resolver group should be = IT Salesforce

 

I triedj to split them into 10 separate rules (branches), but the drawback is that Jira will count every automation against our monthly usage even 9 of 10 scripts were not successful. That's why I was looking for another option.

Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 20, 2023

Thank you for the explanation. I also understand the reasoning behind combining them since we had similar thoughts for our automation rules.

Atlassian lists in their documentation what does not count towards your monthly usage. Based on that information, we rewrote some of our rules to always start with a condition if possible. Why? If the condition equals to false, the automation won't count towards your limit.

I have the impression, you can write your rules that way that you put the condition on top which should result in "NO ACTION" for most of your rules. All these rules won't count towards your limit.

Would that work?

Zaldy Parian
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.
November 21, 2023

Hi @Matthias Gaiser _K15t_ ,

That's a great idea. I was under the impression the whether the rule is successful or not, it will count against the monthly allocation.

Anyway, would you mind sharing a sample of automation rule that starts with a condition that would potentially results to No Action?

 

Thanks again.

Like Matthias Gaiser _K15t_ likes this
Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 21, 2023

Happy to do so, @Zaldy Parian

Here are two screenshots from our support instance:

The Rule

In this rule, we first check the issue with two conditions (is the comment a public comment and does it contain a link to our public issue tracker).
If this is successful, we perform various actions, starting with a lookup table and eventually linking some issues in the end.

rule.png

The Audit log

For most executions of this rule, the condition above results to false, and therefore won't perform any actions. It will then look like this in the audit.log

audit-log.png

All the best for creating your automation rules!

Matthias.

Zaldy Parian
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.
November 21, 2023

Cheers, mate. Will give it a go soon.
Appreciate it heaps.

Like Matthias Gaiser _K15t_ likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events