Forums

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

Groovy script to set value as Date

Tam Tran March 25, 2019

Hi,

I can use below method to set new value for an attribute (as instruction from Insight document site)

public MutableObjectAttributeBean createObjectAttributeBeanForObject(ObjectBean objectBean,
                                                                     ObjectTypeAttributeBean ota,
                                                                     String... values)
                                                              throws InsightException

Now, I need to get value from a Jira Date Picker and set it to Insight attribute as Date format.

I think I need to use this method:

public MutableObjectAttributeBean createObjectAttributeBeanForObject(ObjectBean objectBean,
                                                                     ObjectTypeAttributeBean ota,
                                                                     DateFormat dateFormat,
                                                                     DateFormat dateTimeFormat,
                                                                     String... values)
                                                              throws InsightException

However, I do not know how to declare DateFormat. Could you please give me any suggestion? 

Best regards,

Tam

1 answer

0 votes
PD Sheehan
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.
June 16, 2020

I was looking for the same information ... and after failing to find anything in the community, I figured a way to set the date value.

I could not find how to use the createObjectAttributeBeanForObject(ObjeacBean objectBean, ObjectTypeAttributeBean ota, DateFormat dateFormat, DateFormat dateFormat, String value) signature, but the following worked for me (assumed you already have facades and factories loaded)

def testObjectId = 62410
def dateAttributeId = 198
def object = objectFacade.loadObjectBean(testObjectId)

def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(dateAttributeId )
def objectAttributeBean = object.createObjectAttributeBean(objectTypeAttributeBean)
def objectAtrributeValueBean = objectAttributeBean.createObjectAttributeValueBean()
objectAtrributeValueBean.setDateValue(new Date())
objectAttributeBean.setObjectAttributeValueBeans([valBean])
objectFacade.storeObjectAttributeBean(objectAttributeBean)
Tam Tran June 16, 2020

Thanks @PD Sheehan 

Maybe my direction was wrong from the beginning then I figured out the other easier way. That is converting the value to string so that it can be stored to Insight attribute.

// CF 10357 is Date Picker

CustomField toDateCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10357);

def toDateValue = issue.getCustomFieldValue(toDateCustomField);

str_toDateValue = DateFormat.getDateInstance().format(toDateValue);



Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events