Forums

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

Fill select list custom field from scriptrunner mail-handler

Bob
Contributor
August 9, 2019

I can't seem to get my script runner mail-handler to fill a custom field of the type "select list". 

Is this possible using the messageHandlerContext.createIssue? 

1 answer

1 accepted

0 votes
Answer accepted
PD Sheehan
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 9, 2019

I haven't played with the new mail-handler yet ... but have you looked up how to generally set a select custom field using scriptrunner? There are loads of examples here on the community.

 

My guess, after a quick read of the documentation, is that the messageHandlerContext.createIssue requires an issueObject created with issueFactory

From there you will need something like this

/* what comes before to get issueObject*/

def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

//get the custom field and all the options relevant for the current issue
def mySelectCf = customFieldManager.getCustomFieldObject('customfield_xxxxxx')
//alternate method for getting custom field, not safe if same name is used more than once
//def mySelectCf = customFieldManager.getCustomFieldObjectByName('Select List Friendly Name')
def mySelectContextConfig = mySelectCf.getRelevantConfig(issueObject)
def selectOptions = optionsManager.getOptions(mySelectContextConfig)

//find the option you want to apply
def myOption = selectOptions.find{it.value == 'MySelectValue'}

if(myOption){
issueObject.setCustomFieldValue(mySelectCf, myOption)
}

messageHandlerContext.createIssue(user, issueObject)

Bob
Contributor
August 10, 2019

Hi Peter-Dave, 

Now this makes me feel silly. Had to get the relevant config after defining the issueobject. Weekend was past due. It works just fine. 

My apologies and gratitude,

 

Bob

Suggest an answer

Log in or Sign up to answer