Script Runner - set Field "Customer Request type"

Is it possible to set the Field "Customer Request type" via a scriptrunner postfunction in a Service Desk Workflow?

2 answers

Hi,

So Jonny is right saying that 'Service Desk fields can be a bit tricky' and his script is 100% correct for a single select list (as he did mention). But the Customer Request Type does not behave as a Single Select list. So ...

import com.atlassian.jira.component.ComponentAccessor

// In order to find the key of it select an request type for an issue and then navigate to
// http://<baseUrl>/rest/api/2/issue/<issueKey>?expand=renderedFields,editmeta
// and next to the id of the Customer Request Type custom field (see below in log) you will find it
def REPORT_SYSTEM_PROBLEM_KEY = "sdp/systemproblem"

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")

// get the id of the cf in the logs in order to use it for finding the key of the Customer Request Type
log.debug("Customer Request Type Custom field Id: ${tgtField.getId()}")

def requestType = tgtField.getCustomFieldType().getSingularObjectFromString(REPORT_SYSTEM_PROBLEM_KEY)
issue.setCustomFieldValue(tgtField, requestType)

hope that helps, Thanos

if u stumble over this...

 

the request type in: 

issue.setCustomFieldValue(tgtField, requestType)

 

has to be the key NOT the id you grab from the rest api or the logs.

only the according entry to:

 

sdp/systemproblem

Btw, it seems that you do not have to be successful in setting a correct type.

After setCustomFiel..the request will show up in the customer portal, even if the type shows NULL in the issue itself..

EDIT: See Thanos's answer, above. This is not quite right.

Service Desk fields can be a bit tricky, but I have seen examples of setting it via Behaviours (e.g. https://answers.atlassian.com/questions/15836926).

If it behaves like other fields in the context of Post Functions, then you could do something like:

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def crtField = customFieldManager.getCustomFieldObjects(issue).find{it.name == "Customer Request Type"}
issue.setCustomFieldValue(crtField, "Desired Request Type")

 

It may be that the Customer Request Type behaves like a select list, in which case, you may need to bring in the Options manager.

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def crtField = customFieldManager.getCustomFieldObjects(issue).find{it.name == "Customer Request Type"}
def fieldConfig = crtField.getRelevantConfig(issue)
def options = optionsManager.getOptions(fieldConfig)
def optionToPick = options.find{it.value == "Desired value"}
issue.setCustomFieldValue(crtField, optionToPick)

 

Hello. I tried to use that "select list options" code snippet with Customer Request Type field but it does not work.

Here are some ways to retrieve "project/UUID" expected values for this custom field:

- inspect jira page DOM to look for select option

- query database thanks 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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

70 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you