I am trying to use the below script to pull the value from one field and apply it to a single Group picker. I have seen this script in another discussion and it worked for them, but I am not sure why it is not working for me. I would like to add this script as a listener for whenever the ticket is updated. Is there any way to make the listener only trigger when a specific custom field is updated? Below is the script that is failing for me:
import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.getCustomFieldManager() def groupManager = ComponentAccessor.getGroupManager() def assignGroupField = customFieldManager.getCustomFieldObjectByName("Test Group") def assignedGroupValue = customFieldManager.getCustomFieldObject("customfield_10601") def assignableGroup = groupManager.getGroup(assignedGroupValue) //jira group issue.setCustomFieldValue(assignGroupField, assignableGroup)
In this instance, Custom Field 10601 is where the value is currently. This is an Insight Custom field. I need to take the text from that field, and apply it as a group in the field called "Test Group".
As part of this script, is there any way to add a component that manipulates the text before it adds it to Test Group? I was wondering if I could use the 'substringBefore' function to only utilize part of the text?
Behavior initializer run before the fields are populated from the data associated with the issue (from the database).
So to check if a field already has a value in the initializer, you want to look at the binding variable "underlyingIssue" and load those values from that issue object
Something like
def fieldName = 'Board Summary Outcome for Applicant'
def outcome
if(underlyingIssue){
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(underlyingIssue).find{it.name == fieldName}
def outcome = underlyingIssue.getCustomFieldValue(cf)
} else {
//underlyingIssue is null on issue create screen
outcome = ''
}
if(!outcome){
getFieldByName(fieldName).setFormValue("Dummy Text Here.")
}
Thanks Peter - worked a treat. I've modified your initial code block slightly as you defined outcome twice and the block is missing an import to enable the use of the ComponentAssessor.
import com.atlassian.jira.component.ComponentAccessor;
def fieldName = 'Board Summary Outcome for Applicant'
def outcome
if(underlyingIssue){
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(underlyingIssue).find{it.name == fieldName}
outcome = underlyingIssue.getCustomFieldValue(cf)
} else {
outcome = ''
}
if(!outcome){
getFieldByName(fieldName).setFormValue("Dummy Text Here.")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah I wrote all that directly in the answer box... not in an actual environment, so it was all from memory. I assumed you might have had the ComponentAccessor import already for other aspects of your script.
The double def was just me deciding to define it outside the if block mid-way through my response and not being very diligent in reviewing.
Glad I pointed you in the correct direction. Don't forget to accept the answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.