Set Summary Based n Insight Custom Field in a Post function

Marco Hasenfratz November 16, 2021

Hi Everybody,

i try to write a Scriptrunner Scrip in a Postfunction (Creation of ISSUE) to set the Summary based on a Value which comes from an Insight Object.

 

Tried the following:

import customRiadaLibraries.insightmanager.InsightManagerForScriptrunner
import customRiadaLibraries.insightmanager.SimplifiedAttachmentBean
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY

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

def text = objectFacade.loadObjectBean(insightKey)?.label
summary.setFormValue("Request for ${text}")

 

But i always get this error:

2021-11-16 17:35:39,775 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue IAM-6 for user 'liha03'. View here: http://jira.aspecta.li:8080/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=IAM%3A+Workflow+for+IAM+Order+%2F+Modify+Jira+Service+Desk&descriptorTab=postfunctions&workflowTransition=211&highlight=1
java.lang.NullPointerException: Cannot invoke method getFieldIdByName() on null object
	at com.onresolve.jira.groovy.Behaviour$getFieldIdByName$2.call(Unknown Source)
	at com.onresolve.jira.groovy.user.FieldBehaviours.getFieldByName(FieldBehaviours.groovy:71)
	at Script137.run(Script137.groovy:11)

What am I doing wrong?

Thank you in advance.

Marco

1 answer

1 accepted

0 votes
Answer accepted
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 16, 2021

Disclaimer: I've used Scriptrunner in the past but don't have access to it now. My information is coming from reviewing the documentation.

The getFieldByName and getFieldIdByName functions apply to getting data from a Form. When you are in a Post Function, any Form associated with the transition is no long available.

In your function I believe you need to reference the issue against which the transition is occurring.

Here is one example. Others can be found by doing an internet search for "jira scriptrunner groovy set value in post function"

https://library.adaptavist.com/entity/change-the-value-of-a-custom-field-in-a-post-function

Marco Hasenfratz August 29, 2022

Perfect, thank you!

Suggest an answer

Log in or Sign up to answer