Forums

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

ScriptRunner Send Notification Post Function Formating

Matt Noe
Contributor
October 29, 2020

I've created a post function send notification via ScriptRunner, but the output formatting is less than desirable.

Everything within the script runs together, and for some of the fields, I see the URL for the fields.

Is there a way to prevent the URLs from showing? 

Is there a way to format the output so it doesn't write in one blob (does HTML code need to be part of my script?)?

I did make one attempt to correct both problems based on another article in the community which is in my Primary Domain info.

My script:

def fields = get('/rest/api/2/field')
.asObject(List)
.body as List<Map>


"""The request ${issue.key}, requires an initial estimate by ${((List)issue.fields.customfield_10133)}.

Primary Domain: <%out<<issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Primary Domain"))%>

Applications: ${((List)issue.fields.customfield_10127)}

Business Requirements: ${issue.fields.customfield_10126}

Regards,
JIRA Team"""

 

Email Output:

The request CBE-8633, requires an initial estimate by [[self:https://mysite.atlassian.net/rest/api/2/customFieldOption/10139, id:10139, value:Accenture]]. Primary Domain: <%out<<issue.getcustomfieldvalue(com.atlassian.jira.component.componentaccessor.getcustomfieldmanager().getcustomfieldobjectbyname("primary domain?))%=""> Applications: [[self:https://mysite.atlassian.net/rest/api/2/customFieldOption/10307, id:10307, value:GEP - P2P]] Business Requirements: There is an issue in which the accounting codes aren't coming over correctly into Great Plains, I've attached a recording of the issue. Debbie Felix mentioned that this issue was already fixed for the CBI instance but, the issue is still happening in the CBT, CBV, and Retail instances. The CBI issue that was fixed was under ERO 10031, I've attached an email thread from Debbie discussing this ERO with the Accenture team. Regards, JIRA Team 

1 answer

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
October 30, 2020

Hi Matt,

Thank you for your question.

I can confirm in your script above that when you are gteting the custom fields that you are just returning the whole custom fields and not the properties within them which is why you see a whole URL.

You will notice in the object that this returns that the fields have a value paramater stored inside them which stores the value of the field and you should make sure you access the value paramater when getting the field in order to display just the value in the email. 

As an example using the Applications field this means you should get the value out of it by changing the line to be similar to Applications: ${issue.fields.customfield_10127.value}

Also, I notice for the Primary Domain field the code you have here is for Jira server as this calls the Java API and will not work so this will just print this as a string and you should update this to access the Primary Domain or Applications field in a similar way to how you access the customfield_10133 field.

Finally, I can confirm that you can specify HTML in the message to format this as you require.

I hope this information helps.

Regards,

Kristian

Matt Noe
Contributor
November 9, 2020

@Kristian Walker _Adaptavist_  Thank you for the information.  I've figured out nearly every field, but I am having trouble getting the value back from a single select people picker custom field.  It appears to behave differently than a single select list.

 

Would you please share how I would retrieve a custom field people picker value?

Kristian Walker _Adaptavist_
Community Champion
November 9, 2020

Hi Matt,

Thank you for your response.

I can confirm the best way to identify how fields are stored on an issue is to navigate to the Script Console page and then to click the Get Issue Fields link in the Examples section below the code box. 

This will then populate the code box with a script where you can specify the issue key for an issue that has the User Picker field set on it in order to see how the data for this field is stored.

Running this example script will then return the JSON format showing all fields on an issue and it will show what properties are stored below the user picker field and allow you to determine what syntax should be used to extract the value from this field.

I hope this information helps.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events