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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner post-function - Update SD Request Type

Hi community,

I am trying to use a ScriptRunner post-function to clone a SD Request into a new SD Request. How can I define the Request Type of the newly created SD Request?

I followed these instructions:

https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Script-Runner-set-Field-quot-Customer-Request-type-quot/qaq-p/44063

https://community.atlassian.com/t5/Answers-Developer-Questions/Set-JIRA-Service-Desk-Custom-Field-in-groovy/qaq-p/518940

But I am not able to find a Request ID that should look something like "support/incident-report". In the Rest of such Request, I can only locate a numeric ID (43 in the example below):

"customfield_11002":{"_links":{"jiraRest":"[BASE_URL]/rest/api/2/issue/16757","web":"[BASE_URL]/servicedesk/customer/portal/1/SDRE-71","self":"[BASE_URL]/rest/servicedeskapi/request/16757"},"requestType":{"id":"43","_links":{"self":"[BASE_URL]/rest/servicedeskapi/servicedesk/1/requesttype/43"},"name":"Boîte aux lettres Outlook","description":"Demande d'une nouvelle boîte aux lettres Outlook","helpText":"","serviceDeskId":"1","groupIds":["3"],"icon":{"id":"11704","_links":{"iconUrls":{"48x48":"[BASE_URL]/secure/viewavatar?avatarType=SD_REQTYPE&size=large&avatarId=11704","24x24":"[BASE_URL]/secure/viewavatar?avatarType=SD_REQTYPE&size=small&avatarId=11704","16x16":"[BASE_URL]/secure/viewavatar?avatarType=SD_REQTYPE&size=xsmall&avatarId=11704","32x32":"[BASE_URL]/secure/viewavatar?avatarType=SD_REQTYPE&size=medium&avatarId=11704"}}}},"currentStatus":{"status":"En attente d'approbation","statusDate":{"iso8601":"2020-11-05T06:22:00+0100","jira":"2020-11-05T06:22:00.493+0100","friendly":"5 minutes ago","epochMillis":1604553720493}}}

With the ID 43 in the following post-function script, the Request Type remains empty in the newly created Request:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder

issue.summary = 'Boîte aux lettres Outlook'

// Customer Request Type custom field (added by JIRA Service Desk)
final String SERVICE_DESK_REQUEST_CUSTOMFIELD = "customfield_11002"

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField requestTypeField = customFieldManager.getCustomFieldObject(SERVICE_DESK_REQUEST_CUSTOMFIELD)
String issueType = issue.getIssueTypeObject().getName();

// Customer Request Type ID (Boîte aux lettres)
String requestTypeValue = "43";
if (requestTypeValue != null) {
	IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
	def requestType = requestTypeField.getCustomFieldType().getSingularObjectFromString(requestTypeValue)
	requestTypeField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(requestTypeField), requestType), changeHolder)
}

I am wondering if there is an issue with the Request ID or if there is something else.

Thanks in advance for your help.
Cheers,

David

1 answer

1 accepted

0 votes
Answer accepted

I solved my issue: I found the correct Request Type ID using the Export->XML feature.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

342 views 3 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you