How to update custom field value?

Hello everyone!, here's my issue:

We have two customf fields:

Customfield1=> Date Type

Customfield2=> Label Type

Objective is after transition to closed status, customfield2 get updated automatically from customfield1 value, i. e.,

if customfieldvalue1  = 11/20/2015

then customfieldvalue2 = 201511   (YYYYMM format)

 

I tried a DB trigger approach, but dashboards didn't get refreshed until reindex.

Then, I tried go for a Post Function approach, but can't get it.

 

I'm using "Script Post-Function"=>

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.issue.util.IssueChangeHolder

import com.atlassian.jira.issue.ModifiedValue

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();

Issue issue  = issue

def cfPrId = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Customfield2'}

cfPrId.updateValue(null, issue, new ModifiedValue("do_something_to_customfield1_to_obtain_YYYYMM_format", issue.getId().toString()), changeHolder);

 

Please any advice would ver appreciated!

 

Regards.

 

Tito.

 

 

2 answers

Hi Tito,

Try to get the issue through the event (Issue issue = event.issue)

PS. Try to use componentAccessor instead of componentManager

So your only problem is - How do I get a String in 'YYYYMM format' from Customfield1=> Date Type?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

828 views 2 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you