Forums

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

Setting Insight Value withe a Listener

Till Horstkamp August 31, 2021

Hey, 
im trying to set up a Listener that stores a Date from a JCF into a Insight Attribute.  I cant do it with the standart Postfunctions in a transition do to Workflow resons so i have to build my own. 
There is something worng with the AtrributeValueBean but i  cant figure out what it ist. 


def insight_objekt = issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10300))[0] 
def insight_v= objectFacade.loadObjectAttributeBean(insight_objekt.getId(), 726).getObjectAttributeValueBeans()[0].getValue()
log.warn insight_v    //Just show the data of the fild i want to acces

def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(726).createMutable() //726
log.warn objectTypeAttributeBean
def objectAttributeBean = insight_objekt.createObjectAttributeBean(objectTypeAttributeBean)
log.warn objectAttributeBean
def objectAtrributeValueBean = objectAttributeBean.createObjectAttributeValueBean()
log.warn objectAtrributeValueBean

def CF_naechste = customFieldManager.getCustomFieldObject(12010)  //Date Format 
DateValue = issue.getCustomFieldValue(CF_naechste)
log.warn DateValue

objectAtrributeValueBean.setDateValue(new Date(DateValue.getTime()))
log.warn objectAtrributeValueBean
objectAttributeBean.setObjectAttributeValueBeans(objectAtrributeValueBean)  // line 82 

objectFacade.storeObjectAttributeBean(objectAttributeBean);



Logs:
2021-08-31 13:14:02,008 WARN [runner.ScriptBindingsManager]: ObjectTypeAttributeBean [id=726, name=Nächste Wartung, type=DEFAULT, defaultType=DATE] 2021-08-31 13:14:02,008 WARN [runner.ScriptBindingsManager]: ObjectAttributeBean [objectTypeAttributeId=726, objectId=7136] 2021-08-31 13:14:02,008 WARN [runner.ScriptBindingsManager]: [null(null)] 2021-08-31 13:14:02,008 WARN  WARN [runner.ScriptBindingsManager]: 2027-04-19 00:00:00.0 2021-08-31 13:14:02,009 WARN [runner.ScriptBindingsManager]: [null(2027-04-19)] 2021-08-31 13:14:02,012 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2021-08-31 13:14:02,012 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null groovy.lang.MissingMethodException: No signature of method: com.riadalabs.jira.plugins.insight.services.model.MutableObjectAttributeBean.setObjectAttributeValueBeans() is applicable for argument types: (com.riadalabs.jira.plugins.insight.services.model.MutableObjectAttributeValueBean) values: [[null(2027-04-19)]] Possible solutions: setObjectAttributeValueBeans(java.util.List), getObjectAttributeValueBeans(), getObjectAttributeValueBeans() at Script4330.run(Script4330.groovy:82)

 

1 answer

1 accepted

0 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
August 31, 2021

Hi , I didn't test it but the exception says you need to use List of values as an argument, but you use  MutableObjectAttributeValueBean.

Did you try to use following code which sets objectAttributeValueBean as an item of the ArrayList?

 

def attributeValueBeans = [objectAtrributeValueBean]
objectAttributeBean.setObjectAttributeValueBeans(attributeValueBeans)
Till Horstkamp September 2, 2021
def attributeValueBeans = [new Date(DateValue.getTime())]
log.warn attributeValueBeans
objectAttributeBean.setObjectAttributeValueBeans(attributeValueBeans) //Line 81
//objectAtrributeValueBean.setDateValue(new Date(DateValue.getTime()))
log.warn objectAtrributeValueBean


2021-09-02 09:48:38,906 WARN [runner.ScriptBindingsManager]: ObjectTypeAttributeBean [id=726, name=Nächste Wartung, type=DEFAULT, defaultType=DATE] 2021-09-02 09:48:38,906 WARN  [objectTypeAttributeId=726, objectId=7136] 2021-09-02 09:48:38,906 WARN [runner.ScriptBindingsManager]: [null(null)] 2021-09-02 09:48:38,907 WARN [runner.ScriptBindingsManager]: Done 2021-09-02 09:48:38,907 WARN [runner.ScriptBindingsManager]: 2024-02-19 00:00:00.0 2021-09-02 09:48:38,907 WARN [runner.ScriptBindingsManager]: [2024-02-19] 2021-09-02 09:48:38,910 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2021-09-02 09:48:38,911 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null java.lang.ClassCastException: java.sql.Date cannot be cast to com.riadalabs.jira.plugins.insight.services.model.ObjectAttributeValueBean at com.riadalabs.jira.plugins.insight.services.model.MutableObjectAttributeBean.setObjectAttributeValueBeans(MutableObjectAttributeBean.java:48) at com.riadalabs.jira.plugins.insight.services.model.MutableObjectAttributeBean$setObjectAttributeValueBeans$0.call(Unknown Source) at Script4838.run(Script4838.groovy:81)


Till Horstkamp September 2, 2021

So the Attribut Variable is still not quit right.  
I mean the dataformat ist like this [null(null)]  but still my format is [2024-02-19]   so yeah still somthing is worng 

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
September 2, 2021

Hi @Till Horstkamp , you didn't adjust the script properly. You need to create a List from objectAttributeBean object, not the date values

 

objectAtrributeValueBean.setDateValue(new Date(DateValue.getTime()))

def attributeValueBeans = [objectAtrributeValueBean]
objectAttributeBean.setObjectAttributeValueBeans(attributeValueBeans)
Like Till Horstkamp likes this
Till Horstkamp September 2, 2021

That works, thanks :) 

Suggest an answer

Log in or Sign up to answer