Behavior to set summary based on custom field values

Cinnober Admins February 8, 2018

I've tried this a few different ways, but I keep getting "null+null".

Any ideas on what I'm doing wrong?

It's a behavior validation script places on the summary field (which is hidden), and runs on the create action.

The custom fields "system" and "access" are radio buttons. 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY

@BaseScript FieldBehaviours fieldBehaviours

def system = getFieldByName("System").value
def access = getFieldByName("Access").value
def summary = getFieldById("summary")


summary.setFormValue("${system} + ${access}")

 

 

 

1 answer

1 accepted

2 votes
Answer accepted
Kyle Moseley
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.
February 8, 2018

It's probably due to the summary being hidden. Is that being done through the field config? If so, you may need to show it via the field config but then hide it via Behaviours. If JIRA isn't delivering the summary field to the rendered page in your browser, the Behaviours JS may not be able to find it with your 'getFieldById'.

Cinnober Admins February 8, 2018

Hey thanks @Kyle Moseley, it's only hidden in the behavior. I think the problem is that once the summary is set, it's not overwriting the summary with the new values. 

So before the custom field value is entered it's already set to "null" so the updated values aren't being caught by the script.  But, I'm not sure how to force it to load those values after they're entered in the form. 

Kyle Moseley
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.
February 8, 2018

And you have the script duplicated on both the Initialiser and the Summary Field? Just confirming if I'm understanding.

 

EDIT: May be worth extending the code to also the two Radio fields, so the script is triggered on their edits.

Cinnober Admins February 8, 2018

No, it's only a validator for Summary field with the condition that it only runs on the "Create" action. 

It works if the summary is deleted from the form. Then it reloads with the correct values of the custom fields. 

I guess I need to find a way to have it reload the summary every time the custom field values are changed? 

Cinnober Admins February 8, 2018

Just saw your edit, yes ! Do you know how I can do that ?

Kyle Moseley
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.
February 8, 2018

Yes, just add the same script to the fields as you did for Summary. Same method as below:

I have found that when I am triggering actions from multiple CFs on a page, I end up duplicating the script on each field. So it will look a bit strange on the Behaviours interface side (seeing the same script 4 times), but ultimately works.

Cinnober Admins February 8, 2018

Ahah !! Cool, it works ! Thanks :) 

Kyle Moseley
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.
February 8, 2018

Awesome, happy to help. Please mark the reply as an accepted answer.

Suggest an answer

Log in or Sign up to answer