Hi Team,
Is it possible to automatically fill in the custom field (a single-user picker) with the Reporter's name when transitioning from status A to status B? When we move from A to B, a transition screen appears with the custom field already present, we want the Reporter's name to be automatically populated in that custom field.
EDIT: Scriptrunner example updated based on further testing.
Hello Lakshmi,
You can set a default value for a single user picker using Scriptrunner Behaviors or Power Scripts Live Fields. I will detail both below.
To limit the screen to a particular transition, you could do something like:
// if (fieldScreen.name == "Approved Screen") {
def reporter = underlyingIssue.getReporter().name
getFieldByName("userPickerSingle").setFormValue(reporter)
// }
For a full example with the necessary class imports, see:
https://library.adaptavist.com/entity/limit-behaviour-to-screen
To get the name of the transition print it out during a transition. See:
https://scriptrunner-docs.connect.adaptavist.com/jiracloud/script-console.html
The main script would look something like the following. Change "trans_21" to the name of the transition and "singleUserPicker" to the name or id of the Single User Picker.
if (argv["screen"] == "trans_21") {
lfSet("singleUserPicker", reporter);
}
To get the name of the transition, print out the value for argv["screen"] during the transition. For example:
printInFile("debug.txt", "Screen value: " + argv["screen"]);
See this documentation on using Live Fields:
https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15488008/Live+Fields
Let us know how it goes!
Regards,
Hyrum
Please note that I work for Appfire and support Power Scripts.
Thank you @Hyrum Steffensen _Appfire_ for your quick response.
Did I miss anything here? I'm receiving an error in the script. I added as server script in the behavior.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure thing, Lakshmi!
Try using "underlyingIssue" instead of "issue". I tested the following and it works.
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
log.error("fieldScreen.name: " + fieldScreen.name)
// if (fieldScreen.name == "Approved Screen") {
def reporter = underlyingIssue.getReporter().name
log.error("Reporter name: " + reporter)
getFieldByName("userPickerSingle").setFormValue(reporter)
// }
I also added some logging for debugging. These will show up in the Jira system logs. Remember to remove the lines with "log.error" before deploying the code to a production environment. The "error" logging level will spam your system and consume lots of system resources.
See this on using logging in Scriptrunner:
https://docs.adaptavist.com/sr4js/latest/best-practices/logging/advanced-logging
Hyrum
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to help, Lakshmi!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Hyrum Steffensen _Appfire_ ,
Is it feasible to switch to a different user? The script transfers information from the "Reporter" to the "Owner" field. However, if I want to change to another user in the same field and not display the reporter on the same transition, I cannot update it. Is there a resolution to this issue?
Also, is it possible to only input the Reporter if the Owner field is blank? If there is already a value, it should just leave that value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Lakshmi,
If you wish to set the value of "Owner" based on the value of another field, make sure that field has been added to the Scriptrunner configuration. Then, move the server-side script to that field. You can then get the changes of that field by using the getFieldChanged() methods.
In the example below, I got the user input for "selectList", then changed the value for "userPicker" based on the option selected.
Note how I am getting the user input value using the following line:
def selectList = getFieldById(getFieldChanged())
Here is the complete script:
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
def selectList = getFieldById(getFieldChanged())
log.error("getFieldChanged(): " + selectList.getValue())
if (selectList.getValue() == "option1") {
def reporter = underlyingIssue.getReporter().name
getFieldByName("userPicker").setFormValue(reporter)
} else if (selectList.getValue() == "option2") {
getFieldByName("userPicker").setFormValue("charlie")
}
If you wish to set the "userPicker" (Owner) field only when it is empty, add the userPicker field in the Behaviours configuration, then do something like the following in the initializer script:
if (getFieldByName("userPicker").getValue() == null) {
getFieldByName("userPicker").setFormValue("charlie")
}
Hope that helps!
Hyrum
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.