Hi guys,
I'm currently trying to make a little script to help me link issues between JSM projects.
One part of my script is to get the correct batch of issues to link to my targeted issue.
In order to do this, I'm running a JQL request and I want a dynamic value in it regarding the Organizations field.
It seems like my current code is working as I'm logging the correct value. However I get a static type checking error and I would like to know how I could get ride of it?
Thanks for your help,
PS : already did a ton of researches ;)
def issueManager = ComponentAccessor.getIssueManager()
def currentIssue = issueManager.getIssueObject("SBDDS-177")
def cfm = ComponentAccessor.getCustomFieldManager()
def cfOrg = currentIssue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_11608"))
log.warn (cfOrg)
def cfValue = cfOrg.name[0]
log.warn (cfValue)
def jql = jqlParser.parseQuery("Organisations = \"${cfValue}\" AND statusCategory != Done")
2022-02-04 15:41:41,617 WARN [runner.ScriptBindingsManager]: [CustomerOrganizationImpl{id=588, name=ACME}]
2022-02-04 15:41:41,617 WARN [runner.ScriptBindingsManager]: ACME
If you run this in your console,
import com.atlassian.jira.component.ComponentAccessor
def issue = ComponentAccessor.issueManager.getIssueObject('KEY-123')
def orgCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Organizations')
issue.getCustomFieldValue(orgCf)*.getClass()
You should see this result:
[class com.atlassian.servicedesk.internal.feature.organization.model.CustomerOrganizationImpl]
So if you want to get rid of the static type checking, you can cast your value to that class (or its interface)
So just expanding on what I have up there, I can get the org(s) name without any static type checking errors:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.servicedesk.api.organization.CustomerOrganization
@WithPlugin("com.atlassian.servicedesk")
def issue = ComponentAccessor.issueManager.getIssueObject('KEY-123')
def orgCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Organizations')[0]
def orgValues = issue.getCustomFieldValue(orgCf) as List<CustomerOrganization>
orgValues*.name
The "as List<CustomerOrganization>" tells the static type checker what type to expect.
Bonus... you also get ctrl-space auto-complete.
Hi Peter-Dave,
Thanks a lot for your very didactic answer ;)
It worked and I even got a new shorcut!
Florian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.