Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner: How to write condition for Customer Request Type (Service Desk)

LendingClub Admin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 27, 2017

Hi All,

I am trying implement the post function for automatic transition (using ScriptRunner) for certain Service Desk requests and was wondering how I can write a condition to do that?

I tried the following:

issue.get("Customer Request Type") == "IT Help"
issue.get("Customer Request Type").value == "IT Help"
issue.get("Customer Request Type").value.toString() == "IT Help"

Thanks!

1 answer

1 accepted

10 votes
Answer accepted
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.
June 28, 2017

Hi 

So your condition should be 

So the value that the Customer Request Type has is an enigma, because is not the one you see. For example for the IT Help is

isdt/getithelp

So your condition will be

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def requestType = issue.getCustomFieldValue(cf)

passesCondition = requestType == "isdt/getithelp"

 Now in order to find the value you have to use for the comparrison the trick I use is I go to the script console and run the following script

import com.atlassian.jira.component.ComponentAccessor

// get an issue that has the Request Type that you want to find the id for
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ISDT-9")
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
issue.getCustomFieldValue(cf)

Hope that help, 

regards, Thanos

LendingClub Admin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 29, 2017

This worked.  

Thank you!

Like Joe Pursel likes this
Jason Huntowski
Contributor
September 20, 2017 edited

Hey All, 

I am having the same problem, but this is not working for me. I was able to track down the request type value, it is super crazy, but it just throws a false every time. Any thoughts of what I may be doing wrong? 

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def requestType = issue.getCustomFieldValue(cf)

if(requestType == "itsd/1747d241-af6a-4a7a-8514-98e314e3b09c")
{return true}

I am not getting any errors. The execution is successful, so it is hard to understand why it resolving as false. The email just never goes out. This is a custom email post function, just FYI.

Any help would be awesome. This just seems like it should be working.

Thanks,

Jason

Like 3 people like this
Dave Hollinden
Contributor
March 15, 2018

Jason, 

I was attempting the same thing. I found out that requestType is not a string, and so the == comparison won't work. This is how I solved it. 

if(requestType.toString() == "itsd/1747d241-af6a-4a7a-8514-98e314e3b09c")
{return true}

 Best, 

Dave

Like 6 people like this
Payne
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 3, 2019

Old thread, but wanted to thank you for providing the ScriptRunner console trick for getting a request type value. Saved my bacon. :-)

Like Joe Pursel likes this
Joe Pursel
Contributor
February 24, 2021

Thanks to all who helped solve this puzzle. Many thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events