Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Behavior to set summary with insight object name

Edited

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

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}")

Hi @Ilya Turov 

Thanks for the response.

i tried with your updated code but getting an error.

error.png

Did you actually try saving and running it?

Don't pay attention to static type checking.

thank you @Ilya Turov , its working fine.

thanks a lot. :)

Hello,

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

Thank you

@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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

333 views 3 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you