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

Script Runner Post function Run as A User

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

Hi All,

 

Currently, I have a Fast-track post function applied on my workflow which is transitioning the issues to next status based on the custom field values.

Ex- If Request type = XYZ then Issue moved From Manager Approval to Open Status.

But the issue is, currently it is running as default to CurrentUser and I want to change it to a Default user.

I created a script but it's not working. It is showing a warning on 'Issue issue = issue' Could you please assist?

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.Field

ApplicationUser targetuser = ComponentAccessor.userManager.getUserByName('Jira Service Management(Automation)')

Issue issue = issue

ScriptRunnerImpl.runWithUser(targetuser){
MutableIssue mutableIssue = ComponentAccessor.getIssueManager().getIssueObject(issue.id)

}

 

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
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

Hi @Manoj Gangwar,

I'm not sure if you have already found a solution for this.

Could you please clarify what version of Jira and ScriptRunner you are currently using?

Thank you and Kind regards,

Ram

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.
December 13, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

We are using Scriptrunner version - 6.50.0 and Jira Version 8.20.27

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 13, 2023

Hi @Manoj Gangwar

Thank you for getting back and providing the requested information.

It appears you are using an outdated version of ScriptRunner. Please upgrade your ScriptRunner plugin to version 8.17.0 or at least 7.13.0 so that you can use the HAPI feature.

If you intend for the Fast Track transition to execute as a different user, you can use this approach with ScriptRunner's HAPI, i.e.,-

Users.runAs('username') {
issue.issueType.name == 'Story'
}

You will need to add this condition to the Conditions field as shown in the screenshot below:-

 fast_track_config.png

For more information, you can refer to this ScriptRunner HAPI documentation.

Thank you and Kind regards,

Ram

Jeanette Seewald March 27, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

I am having the same request (to have the "fast forwad transition" beeing run as a user that we use for automation processes), but your solution unfortunately doesn't seem to work in my case. The transition is executed, but with the current user instead of the "runas-user".

Do you have an idea, what could be the issue here?

We are currently on scriptrunner v8.20.0 and jira v.4.9.18.

I use following condition in the fast forwar transition postfunction:

 

Users.runAs('bsm-admin') {

    issue.getCustomFieldValue(12101) == null

}

 

Thank you a lot in advance,

Jeanette

 

2024-03-26_173839.jpg

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 26, 2024

Hi @Jeanette Seewald

Sorry for the late reply. 

Looking at your code, it seems that you are performing a validation to check that the Custom Field doesn't have a value. There doesn't appear to be any task after that, so you do not see any output.

You need to try something like:-

Users.runAs('bsm-admin') {
issue.getCustomFieldValue('Some Field Name').toString().length() == 0
}

Thank you and Kind regards,
Ram 

Jeanette Seewald May 27, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

thank you for the response.

Yes, I want to check, if the customfield, which is a multi selection field type, has no checked values and if so, the issue should be transitioned to another status. The transitioning should be run as the admin user.

As the gestCustomfieldValue.toString() returns "null" the length returns 4, I changed it to

Users.runAs('bsm-admin') {

   issue.getCustomFieldValue(12101).toString() == 'null'

}

 

But I still get the same result: the issue is transitioned, but with my user account instead of the defined admin account.

The code needs to be in the "Condition" part and not in the "Additional issue actions" part, doesn't it?

Thank you and best regards,

Jeanette

 

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events