Forums

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

Set Updated field with script

Kiss Zoltán November 13, 2020

Dear everyone,

I have to make a script that writes a calculated value into a new custom field.

Where the problem starts... there are around 30.000 tickets in more than 20 different projects, and updated date must have to stay untouched, cause it's necessary in following previous jobs.

I've tried to fill my custom field and restore the old date value at the same script:
mutIssue.setCustomFieldValue(customfield,value);
mutIssue.setUpdated(existingDate);
im.updateIssue(user, mutIssue, EventDispatchOption.DO_NOT_DISPATCH, false);

and just restore date from change history,
...but it seems like "Updated" field can't be set back to a given timestamp.

Any idea how can I do it?

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 13, 2020

Hi @Kiss Zoltán 

I know, there is a way how to not to touch history items, so maybe "updated" date won't be touched too.

Could you try to update the issue this way?

issue.setCustomFieldValue(customField, valueToSave)
Map<String, ModifiedValue> modifiedFields = issue.getModifiedFields()
FieldLayoutItem fieldLayoutItem =ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(customField)
DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder()
final ModifiedValue modifiedValue = (ModifiedValue) modifiedFields.get(customField.getId())
customField.updateValue(fieldLayoutItem, issue, modifiedValue, issueChangeHolder)

If you won't be able to resolve imports, feel free to get back to me and I will try to prepare nicer script... I just have to leave the office, so I tried to provide FAST help :) 

Have a nice weekend

Suggest an answer

Log in or Sign up to answer