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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,425
Community Members
 
Community Events
184
Community Groups

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?

3 answers

7 votes
Thanos Batagiannis [Adaptavist]
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.
Jan 23, 2017

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

@David Klemme didn't work for me ..

1 vote
Jonny Carter
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.
Jan 18, 2017 • edited Feb 21, 2018

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)

 

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.
Feb 22, 2018

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

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jul 02, 2019

Set Customer request field on create issue: 

 

This is how I did it. 

 
import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.event.type.EventDispatchOption

import com.atlassian.jira.issue.Issue

import org.apache.log4j.Logger

def logs = Logger.getLogger("com.acme.workflows")

logs.warn("Workflow function running...")
//set Customer request type

    def cfCustomerRequestType = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Customer Request Type").first();

    final String SERVICE_REQUEST = "bsdr/5dd969ce-dcf6-46cd-9900-814174943441"

    def customerRequest = cfCustomerRequestType.getCustomFieldType().getSingularObjectFromString(SERVICE_REQUEST)

    logs.warn("customerRequest: " + customerRequest)

    IssueManager issueManager = ComponentAccessor.getIssueManager()

    MutableIssue issueToUpdate =  issueManager.getIssueObject(issue.getId()) as MutableIssue

    issueToUpdate.setCustomFieldValue(cfCustomerRequestType, customerRequest);

    issueManager.updateIssue(issue.getReporterUser(), issueToUpdate, EventDispatchOption.ISSUE_UPDATED, false);

In the variable, SERVICE_REQUEST set the UUID of your desired Customer Request type that you get from the database and it will work. 

 

Regards.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events