Forums

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

Script Behavior to set summary with insight object name

Yogesh Mude
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.
September 18, 2019

Team,

Using below script the summary field is set with insight object Key so I want to set summary with object name instead of Key.

{code}

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 part = getFieldByName("Number").value
def summary = getFieldById("summary")

summary.setFormValue(" Test for ${part}")
{code}

test.png

1 answer

1 accepted

2 votes
Answer accepted
Ilya Turov
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.
September 18, 2019

I feel like in behaviour it always returns string value which is object key, not the stored object itself. Guess, the way of solving it might be like this:

import com.atlassian.jira.component.ComponentAccessor

Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)
def insightKey = getFieldByName("Number").value
def summary = getFieldById("summary")

def part = objectFacade.loadObjectBean(insightKey)?.label
summary.setFormValue(" Test for ${part}")
Yogesh Mude
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.
September 18, 2019

Hi @Ilya Turov 

Thanks for the response.

i tried with your updated code but getting an error.

error.png

Ilya Turov
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.
September 18, 2019

Did you actually try saving and running it?

Don't pay attention to static type checking.

Yogesh Mude
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.
September 18, 2019

thank you @Ilya Turov , its working fine.

thanks a lot. :)

Anna Protopapa
Contributor
February 11, 2021

Hello,

Can I use similar code to return the objecttype of an object?

Thank you

Ilya Turov
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 11, 2021

@Anna Protopapa 
I didn't test it, but looking at javadoc something along those line might work

import com.atlassian.jira.component.ComponentAccessor

Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)

Class objectTypeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade")
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeFacadeClass)

def objectTypeKey = getFieldByName("Number").value
def summary = getFieldById("summary")

def objectTypeId = objectFacade.loadObjectBean(insightKey)?.objectTypeId
def objectTypeName = objectTypeFacade.loadObjectTypeBean(objectTypeId)?.name

summary.setFormValue(" Test for ${objectTypeName}")
Like Anna Protopapa likes this
Anna Protopapa
Contributor
February 15, 2021

Thank you @Ilya Turov!!!! Its working perfect!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events