We are using Scriptrunner and Jira Server, 8.20.11.
As part of our change management process and workflow, a certain individual is the approver based on the type of change. In one case, there are 2 users for a certain change type.
Have a custom script using ScriptRunner post-function to accomplish this need.
I am able to retrieve the value of the single select field that represents the "type of change", however, i'm not able to set the users to the multi-user picker custom field.
My code:
def cfvalue = issue.getCustomFieldValue('Type of Change')
log.warn('Type of Change value = ' + cfvalue.get(null))
if (cfvalue.get(null) ==~ 'Infrastructure')
{
issue.setCustomFieldValue('Approvers','User1');
issue.setCustomFieldValue('Approvers','User2');
}
if (cfvalue.get(null) ==~ 'Operational')
{
issue.setCustomFieldValue('Approvers', 'User3');
}
if (cfvalue.get(null) ==~ 'Software')
{
issue.setCustomFieldValue('Approvers','User4);
}
From the errors, it appears the "user name" has to be an object, but i'm unclear on how to create an object for the users to be used in the setting of the custom field.
Hi @Ashvin
Could you please specify what type of field you are using for the Type of Change? Is it a Single Select List?
I am requesting this so I can provide a sample code.
I am looking forward to your feedback.
Thank you and Kind regards,
Ram
@Ram Kumar Aravindakshan _Adaptavist_ That field is a Cascading Select. I only need the value from the 1st option/select field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ashvin
For your requirement, it would be best that you use ScriptRunner HAPI feature.
With HAPI, all you will need to do is:-
def cascadeFieldValue = issue.getCustomFieldValue('Sample Cascade') as String
issue.set {
if (cascadeFieldValue == '[null:Story]') {
setCustomFieldValue('Sample User Picker', 'ram')
} else if (cascadeFieldValue == '[null:Bug]') {
setCustomFieldValue('Sample User Picker', 'admin')
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
To install HAPI, please update your ScriptRunner plugin to the latest release, i.e. 8.9.0 or at least to version 7.11.0.
Below is a screenshot of the Post-Function configuration:-
Below are a couple of test screenshots for your reference:-
1. I create a new ticket and set the parent value in the Cascade Select List to Strory.
2. Once the issue has been created, I transition the issue to In Progress. As expected, the Sample User Picker is updated to Ram Kumar
3. Next, I transition the issue back to To Do and update the parent value of the Cascade Select List to Bug
4. I transitioned the issue once again to In Progress, and as expected, the Sample User Picker is updated to Admin
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
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.