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
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.

Register now
AUG Leaders

Atlassian Community Events