Hi Dear Community,
I had a problem again after the update, now with JSM. After upgrading to version 5.12.10, the script that sets the value of the 'Customer request type' field stopped working correctly.
On some projects, for some reason the field value just stopped being set.
In other cases it is set, but in the task it is displayed as 'No match'. Maybe someone has encountered this problem and knows how to solve it?
To set the value, I use:
And if you go to the portal, the request type is set correctly.
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def issue = ...
//issue.requestType
def customerReqTypeCF = ComponentAccessor.CustomFieldManager.getCustomFieldObject("customfield_10000")
def key = "es/8513f0d8-16c3-4a36-a41e-73ad733334b2"
def newCustomerReqType = customerReqTypeCF.getCustomFieldType().getSingularObjectFromString(key)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
customerReqTypeCF.updateValue(null, issue, new ModifiedValue("", newCustomerReqType), new DefaultIssueChangeHolder())
ComponentAccessor.issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, true)
UPD.
The problem is that when I set the field value manually and then retrieve the field value by scriptrunner, I get the value 'es/8513f0d8-16c3-4a36-a41e-73ad733334b2'. But if I take a value from another task and set it in test task, I get the field value 'engsup/8513f0d8-16c3-4a36-a41e-73ad733334b2'. It turns out that the value is broken because of a project key that was changed earlier.
Given what you are encountering, I suggest you change your approach to ScriptRunner's HAPI feature and ScriptRunner's Custom Script Post-Function.
Below is a sample working code for your reference:-
issue.set {
if (issue.issueType.name == 'Bug') {
setRequestType('Report a bug')
} else if (issue.issueType.name == 'Support') {
setRequestType('Technical support')
} else if (issue.issueType.name == 'New Feature') {
setRequestType('Suggest a new feature')
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.
Below are the screenshots of the Post-Function configuration.
1. Use the Create or whichever transition you want to add the Post-Function:-
2. Select ScriptRunner's Custom Script Post-Function
3. Add the sample code I have provided above and modify it according to your requirements.
So, in my environment, using the approach above, whenever I create a ticket via the standard Jira interface, the Request type automatically get's updated accordingly.
I hope this helps to solve your issue. :-)
Thank you and Kind regards,
Ram
Hi. Thank you so much for your help!
I found what the problem I had, I described it in my first post.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Stumper DumpelCan you run that script from the console for an individual issue and print the error you get?
You mention that this starts showing up after a JSM upgrade, have you upgraded to the latest version of Scriptrunner?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm already running this script in the console.
SR version 8.30.0.
I also noticed that if I take the value of the 'customer request type' field from another task created through the portal, the correct value is set in the test task.
My guess is that the conversion from string to object stopped working.
def key = "es/8513f0d8-16c3-4a36-a41e-73ad733334b2"
def newCustomerReqType = customerReqTypeCF.getCustomFieldType().getSingularObjectFromString(key)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you check to ensure that the Request Type is valid for your JSM project? For example that you can create the specific request type from the portal or find the value in the dropdown list in the project's issue UI?
Please advise.
Best, Joseph Chung Yin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
Yes, I am using a certain type of request type and a certain type of task as a test.
Requst type in project settings:
Test issue type:
Available request type:
Request type key and name in SR console:
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.