How to subtraction operation Groovy script in insight Post Functions

kahn chang May 23, 2018


I have CustomField:
CustomField 10328 is a standard number field
CustomField 10321 Mapping to insight objectType 100

objectTypeAttribute 1004 of insight objectType 100, type=defailt ,type value=integer

I need Update object attribute 1004 with the value “attribute 1004” Minus “CustomField 10328”

I have no experience. I tried to modify Groovy script examples, but I haven't touched on subtraction yet. I made an error.



import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;

/* Get Insight Object Facade from plugin accessor */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);

/* Get Insight Object Attribute Facade from plugin accessor */
Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass);

/* Get the factory that creates Insight Attributes */
Class objectAttributeBeanFactoryClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(objectAttributeBeanFactoryClass);

/* This is the custom field with the value you want to add to an object attribute */
CustomField jiraCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10328); // Change 10328 to the correct value

/* This is the custom field where the object/s you want to set the value */
CustomField insightCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10321); // Change 10321 to the correct value
def insightObjects = issue.getCustomFieldValue(insightCustomField); // "issue" variable is always accessible in post function scripts.

/* This is the priority object type attribute and the one we want to modify */
def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(1004);

if (insightObjects != null) {
insightObjects.each{insightObject ->
/* Create the new attribute bean based on the value */
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(insightObject, objectTypeAttributeBean, issue.getCustomFieldValue(jiraCustomField));
/* Load the attribute bean */
def objectAttributeBean = objectFacade.loadObjectAttributeBean(insightObject.getId(), objectTypeAttributeBean.getId());
if (objectAttributeBean != null) {
/* If attribute exist reuse the old id for the new attribute */
/* Store the object attribute into Insight. */
try {
objectAttributeBean = objectFacade.storeObjectAttributeBean(newObjectAttributeBean);
} catch (Exception vie) {
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage());

/* Done! :) */
return true;


class com.riadalabs.jira.plugins.insight.common.exception.GroovyInsightException

GroovyInsightException: No signature of method: is applicable for argument types: (,, java.lang.Double) values: [CGO52_ESFP-GE-SX-MM1310_H3C_TEST (NW-737281), ObjectTypeAttributeBean [id=1004, name=StockValue, type=DEFAULT], ...] Possible solutions: createObjectAttributeBeanForObject(,, [Ljava.lang.String;), createObjectAttributeBeanForObject(,, java.text.DateFormat, java.text.DateFormat, [Ljava.lang.String;)'



Please help me!

Best Regards

1 answer

0 votes
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.
May 29, 2018



The createObjectAttributeBeanForObject takes a variable argument of strings as the latest parameter which might not be that intuitive. 

The trace indicates that you got a Double value. 

If you sent the last parameter to the createObjectAttributeBeanForObject as the following


It should do the trick and of course you can switch the inner statement for the result of your arithmetic operation. 

Check out if it solves your use case. 



kahn chang July 5, 2018


Thank you for your answer, but it's too complicated for me. I submitted a new function, because I believe it will be very useful.


Aaron Whigham
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 12, 2023

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events