You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Hi, I have a Scriptrunner Behavior who (on the service desk portal) has to take over the values of an issue selected in an issue picker field in Insight Custom Fields. Only the value of an Insight referenced custom field is not taken over.
This is the script.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)
def issueManager = ComponentAccessor.getIssueManager() as IssueManager
def issuePickerCustomFieldValue = getFieldById(getFieldChanged()).value
def relatedIssue = issueManager.getIssueByCurrentKey(issuePickerCustomFieldValue as String)
def EngineerPACustomField = getFieldByName("Engineer E/PA")
def EngineerPACustomFieldObject = customFieldManager.getCustomFieldObjectsByName("Engineer E/PA")[0]
def EngineerPACustomFieldValue = (EngineerPACustomFieldObject ? relatedIssue.getCustomFieldValue(EngineerPACustomFieldObject) : null) as String
if (EngineerPACustomFieldValue) {
def objectKeyStr = EngineerPACustomFieldValue.substring(EngineerPACustomFieldValue.indexOf("(")+1,EngineerPACustomFieldValue.indexOf(")"))
EngineerPACustomField.setFormValue(objectKeyStr)
}
def SystemIntegratorCustomField = getFieldByName("System integrator")
def SystemIntegratorCustomFieldObject = customFieldManager.getCustomFieldObjectsByName("System integrator")[0]
def SystemIntegratorCustomFieldValue = (SystemIntegratorCustomFieldObject ? relatedIssue.getCustomFieldValue(SystemIntegratorCustomFieldObject) : null) as String
if (SystemIntegratorCustomFieldValue) {
def objectKeyStr1 = SystemIntegratorCustomFieldValue.substring(SystemIntegratorCustomFieldValue.indexOf("(")+1, SystemIntegratorCustomFieldValue.indexOf(")"))
SystemIntegratorCustomField.setFormValue(objectKeyStr1)
}
def MedewSystemIntegratorCustomField = getFieldByName("Medewerker System integrator")
def MedewSystemIntegratorCustomFieldObject = customFieldManager.getCustomFieldObjectsByName("Medewerker System integrator")[0]
def MedewSystemIntegratorCustomFieldValue = (MedewSystemIntegratorCustomFieldObject ? relatedIssue.getCustomFieldValue(MedewSystemIntegratorCustomFieldObject) : null) as String
if (MedewSystemIntegratorCustomFieldValue) {
def objectKeyStr2 = MedewSystemIntegratorCustomFieldValue.substring(MedewSystemIntegratorCustomFieldValue.indexOf("(")+1, MedewSystemIntegratorCustomFieldValue.indexOf(")"))
MedewSystemIntegratorCustomField.setFormValue(objectKeyStr2)
}
"PA Project" is a Issue picker field.
"Medewerker System integrator" is an Insight referenced custom field and this is not copied from the chosen issue.
"Engineer E / PA" (User Picker (single user) field) and "System Integrator" (Insight Object/s field) are copied correctly.
How do I get this working?
regards, Marco
Hi,
I solved it by make for "Medewerker System integrator" a "normal" Insight Custom Field instead of a Insight referenced custom field.
Regards, Marco
I'm not sure why your script is not working... but I have a few tips for you.
1) accessing ObjectFacade and other insight classes is much easier in scriptrunner than in insight groovy console. Try like this:
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin('com.riadalabs.jira.plugins.insight')
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
@PluginModule ObjectFacade objectFacade
3) Behavior FormField obtained by name can return the field ID. That makes findings customFieldObject much easier:
def EngineerPACustomFieldObject = customFieldManager.getCustomFieldObject(EngineerPACustomField.fieldId)
2) Insight custom fields are returning Arrays of Insight ObjectBean (regardless if it allows 1 or many values, except when they are empty). So you don't need to parse the string, just get the object directly
def EngineerPACustomFieldValue = (EngineerPACustomFieldObject ? relatedIssue.getCustomFieldValue(EngineerPACustomFieldObject) : []) as ArrayList<ObjectBean>
if (EngineerPACustomFieldValue) {
def objectKey = EngineerPACustomFieldValue[0].objectKey
/*...*/
}
3) Insight fields in behaviours return a string when a single value is preset and an array of string where there are multiple values. But always require an array of strings when setting the form values (even for just a single value).
So putting it all together and avoiding code repeats ... you should be able to use this:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin('com.riadalabs.jira.plugins.insight')
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
@PluginModule ObjectFacade objectFacade
def issueManager = ComponentAccessor.issueManager
def issuePickerCustomFieldValue = getFieldById(fieldChanged).value
def relatedIssue = issueManager.getIssueObject(issuePickerCustomFieldValue as String)
def fieldNamesToMap = ['Engineer E/PA','System integrator','Medewerker System integrator']
fieldNamesToMap.each{fieldName->
def formField = getFieldByName(fieldName)
def customField = customFieldManager.getCustomFieldObject(formField.fieldId)
if(customField){
def values = (relatedIssue.getCustomFieldValue(customField) ?: []) as ArrayList<ObjectBean>;
if(values){
def objectKeys = values*.objectKey
formField.setFormValue(objectKeys)
}
}
}
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.
If you already heard about Smart Commits in Bitbucket, know that you just stumbled upon something even better (and smarter!): Genius Commits by Better DevOps Automation for Jira Data Center (+ Server...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.