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

Set JIRA Service Desk Custom Field in groovy

Benjamin Dombrowsky [catWorkX] October 21, 2014

Hi,

it is possible to set the "Customer Request Type" Custom Field in groovy?

My first try result: "java.lang.String cannot be cast to com.atlassian.servicedesk.internal.customfields.origin.VpOrigin"

Is there any way?

Thanks!

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Benjamin Dombrowsky [catWorkX] October 21, 2014

I found a solution for me:

 

...

requestTypeCF.getCustomFieldType().getSingularObjectFromString("STRING")

...
Timothy Harris April 19, 2015

I want to set the request participants but don't know the internal custom field type. Seems you have done some scripting with service desk custom fields. Any tips you can pass along?

13 votes
Tom Moors
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.
April 22, 2015

Hi Timothy,

The snippet provided by Benjaminis the one you need to fetch the options that you want to set in your script.

I included an example script that will fill in the JIRA Service Desk Request Type based on the IssueType:

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
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

// Remove these lines if you want to run this script as a post function script
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
Issue issue = ComponentAccessor.getIssueManager().getIssueObject("MYISSUENUMBER-123")

// Change this to the ID of your Customer Request Type custom field (added by JIRA Service Desk)
final String SERVICE_DESK_REQUEST_CUSTOMFIELD = "customfield_11800"
 
// These are the possible values for this specific Service Desk instance - you can check those in your instance by consulting the REST view of an issue:
// http://JIRASERVER/rest/api/2/issue/ISSUENUMBER?expand=renderedFields,editmeta
// In this list you can find the value next to "customfield_11800" (id of the field)
final String INCIDENT_REPORT = "support/incident-report"
final String SERVICE_REQUEST = "support/service-request"

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField requestTypeField = customFieldManager.getCustomFieldObject(SERVICE_DESK_REQUEST_CUSTOMFIELD)
String issueType = issue.getIssueTypeObject().getName();
String requestTypeValue = null;
switch (issueType.toLowerCase()) {
    case "incident":  requestTypeValue = INCIDENT_REPORT;
    	break;
    case "service request": requestTypeValue = SERVICE_REQUEST;
    	break;
    default: break;
}
if (requestTypeValue != null) {
	IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
	def requestType = requestTypeField.getCustomFieldType().getSingularObjectFromString(requestTypeValue)
	requestTypeField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(requestTypeField), requestType), changeHolder)
}

 

Kind regards,

Tom

Deleted user June 2, 2016

This code works like a charm.

Jason Mueller August 17, 2016

Thank you so much, this put me on the right path.

Dastin_Kuwałek__SoftwarePlant_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 23, 2016

When I tried this line of code:

requestTypeField.getCustomFieldType().getSingularObjectFromString("sd/system-access")

In my mind played sweetest symphony. Tom, you are the man!

Additional explanation

The "sd/system-access" is the string which consists of:
  • "sd/" which is the project key followed by slash
  • "system-access" which is the programmatic key for value that can be set in the RequestType field created by Service Desk
Christian Pascher
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.
January 24, 2017

Seems like this isn't working for JSD 3.3 anymore?

 

€: for me, the id was "56973cbb-745f-4d2c-97ea-5bd7a54fd2ae", not a normal string

Antonio Dionisio February 16, 2017

@Christian Pascher I am using JSD 3.3 and this didn't work. The id looks in fact as a "random" String...

Antonio Dionisio March 9, 2017

There is an open issue to solve the key creation inconsistency: https://jira.atlassian.com/browse/JSD-4916

Pascal Uhe August 23, 2018

Is this valid in recent version? I don't get the value of the request type which in this example is set to

support/incident-report   

Where can I find it? And what is the right one?

Yves Martin
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.
August 28, 2018
1 vote
Yves Martin
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.
February 22, 2018

With recent Service Desk version, "Customer Request Type" value consists in a `project/UUID` string which can be found in database table AO_54307E_VIEWPORTFORM (key) in relation with AO_54307E_VIEWPORT (key).

Refer to SQL query available at https://community.atlassian.com/t5/Jira-Service-Desk-questions/Re-set-customer-request-type-with-script-runner/qaq-p/120737/comment-id/1213#M1213

SELECT concat(lower(p.pkey),'/',vform.key) as value FROM jiraissue i , project p, issuetype t ,  AO_54307E_VIEWPORT vport, AO_54307E_VIEWPORTFORM vform WHERE p.id = i.project  AND i.issuetype = t.id AND i.project = vport.project_id AND vport.id = vform.viewport_id AND vform.issue_type_id = t.id AND i.id = 'PROJECT-123';
TAGS
AUG Leaders

Atlassian Community Events