Forums

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

ScriptRunner Add-on user doesn't execute the script

Mark O_Shea May 5, 2021

I'm trying to have a script run as the JIRA ScriptRunner user for the "issue updated" event.

However, it will only ever execute as the user initiating, not the ScriptRunner user. I need the ScriptRunner user to execute this script so that I can do a PUT request into a field not visible on the screen.

I first check to see if we're executing as the "ScriptRunner for Jira" for JIRA user and it is not, as can be seen from the logs where I'm logging the "user" variable inside the script. 

image.png

image.png

Any ideas on how to make the ScriptRunner Add-on user run scripts instead of the Initiating user?

3 answers

1 accepted

0 votes
Answer accepted
Mark O_Shea May 6, 2021

Thanks to everyone who got back to me so promptly!

 

Turns out this was an error on my part. I have written a custom "jira_request" method but was using an older version of the method where I hadn't implemented QueryStrings for PUT requests. 

 

I am still seeing the user in the payload as my user, but the PUT request goes through so I'm not complaining! I actually want to add a catch to stop the script executing if it's not a human user initiating so it works as an advantage to me.

 

The below logs and payload shows that the PUT request finally goes through with the overrideScreenSecurity QuerySting. However the accountId 5d42.. is my account

image (15).png image (16).png

 

Many thanks all,

This is resolved for me.

 

Best,

Mark

0 votes
Kate Kabir
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 5, 2021

Hi @Mark O_Shea 

Thank you for the question.

The user variable will be logged in user which is here the user which is why you are seeing this. If you configure this as the Add on User, the code will run as this user and you can see this by clicking the "Green" tick in the history section, then to the Payload tab.

Hope this helps.

Thank you

Kind Regards

Kate

0 votes
Payne
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 5, 2021

I use the following in a ScriptRunner script in a Jira Server instance; hopefully it will work for you in the Cloud version.

ApplicationUser jiraAdminUser = ComponentAccessor.getUserManager().getUserByName("jiraadmin")
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(jiraAdminUser)
Kristian Walker _Adaptavist_
Community Champion
May 6, 2021

HI Payne,

Unfortunately, this code will not work in ScriptRunner for Jira Cloud as Jira Cloud only provides the rest API's that ScriptRunner can use and does not have the same Java API's like the server version has.

Regards,

Kristian

Like Payne likes this

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, product operations, product ops, linkedin live, atlassian events, cross-functional collaboration, product management, engineering collaboration, design collaboration, atlassian learning, agile teams, product strategy

Product Ops Unpacked: 4️⃣ tips every product pro needs to know ✍️

Join PM Evangelist, Axel Sooriah, & Product Ops. Consultant & Advisor, Jenny Wanger, as they unpack the role of product ops and discuss key takeaways in Atlassian’s ‘The Product Ops Mission’ guide. They’ll answer your questions live on May 6 at 9:00am PT.

Register here ⬇️
AUG Leaders

Atlassian Community Events