Can't change the field value 'Customer request type' by ScriptRunner

Stumper Dumpel July 18, 2024

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?


[ES-6494] Test issue 1.png


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.
Снимок экрана 2024-07-23 112459.png

3 answers

0 votes
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.
July 22, 2024

Hi @Stumper Dumpel

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:-

post_function1.png

2. Select ScriptRunner's Custom Script Post-Function

post_function2.png

3. Add the sample code I have provided above and modify it according to your requirements.

post_function3.png

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

Stumper Dumpel July 23, 2024

Hi. Thank you so much for your help!
I found what the problem I had, I described it in my first post.

0 votes
Adolfo Casari
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.
July 18, 2024

@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?

Stumper Dumpel July 18, 2024

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.

Снимок экрана 2024-07-19 092053.png

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)
0 votes
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 18, 2024

@Stumper Dumpel -

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

 

Stumper Dumpel July 18, 2024

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:
Edit Request Type Group - Service project.png

Test issue type:
Monosnap [ES-6494] Test issue 1.png

Available request type:
123 2024-07-18 2.png
Request type key and name in SR console:
Chrome 2024-07-18.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events