Python script help - Change value of a custom field based on the reporter

Darren Pegg
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.
January 23, 2014

The following checks to see if the budget holder is the same as the reporter if this is true the budget holder is then changed to the Emergency Budget Holder.

If change the else part of the statement to "EmergencyBudgetHolder" it works as a test, but I don't want to be case I want the IF part of the statement to work.. I am assuming its half way there..

JIRA 6.0.8 - Using JIRA Scripting Suite

Within a transition on a post function.

from com.atlassian.jira import ComponentManager

# Only perform functions on Travel Request issues
if(issue.getIssueTypeObject().getId()=="8") :

  cm = ComponentManager.getInstance()
  cfm = cm.getCustomFieldManager()
  im = cm.getIssueManager()

  accountCodeID = issue.getCustomFieldValue(cfm.getCustomFieldObject('customfield_10134'))
  acIssue = im.getIssueObject(int(accountCodeID))
  acBudgetHolder = acIssue.getCustomFieldValue(cfm.getCustomFieldObject('customfield_10070'))
  acEmergencyBudgetHolder = acIssue.getCustomFieldValue(cfm.getCustomFieldObject('customfield_10151'))

  cf=cfm.getCustomFieldObject('customfield_10070')
  if issue.getReporter() == acBudgetHolder :
    cf.getCustomFieldType().updateValue(cf,issue,acEmergencyBudgetHolder)
  else :
    cf.getCustomFieldType().updateValue(cf,issue,acBudgetHolder)

2 answers

0 votes
Darren Pegg
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.
January 26, 2014

The following worked for me,

cf=cfm.getCustomFieldObject('customfield_10070')

  if issue.getReporter().getName() == (acBudgetHolder.getName()):

    cf.getCustomFieldType().updateValue(cf,issue,acEmergencyBudgetHolder)

  else :

    cf.getCustomFieldType().updateValue(cf,issue,acBudgetHolder)

0 votes
Henning Tietgens
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.
January 26, 2014

If you want to update a custom field you should use issue.setCustomFieldValue(cf, value). getCustomFieldType().updateValue() is not correct.

Darren Pegg
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.
January 26, 2014

Hi Henning,

So something like the following?

cf.issue.setCustomFieldValue(cf, acEmergencyBudgetHolder)

Thanks

Henning Tietgens
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.
January 26, 2014

No. Try without cf. at the beginning. issue is a MutableIssue.

Darren Pegg
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.
January 26, 2014

Tried with the following, the issue creates with no error, but the emergency budget holder still does not set..

cf=cfm.getCustomFieldObject('customfield_10070')
if issue.getReporter() == acBudgetHolder :
issue.setCustomFieldValue(cf, acEmergencyBudgetHolder)
else :
issue.setCustomFieldValue(cf, acBudgetHolder)

Henning Tietgens
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.
January 26, 2014

Can you try to log the content of ac..Holder variables before you set the field? You could use log.error() for this.

Is the post function before the post function to create the issue? If yes, you could try to get the IssueManager und call updateIssue() on the issue and place the issue after the create post function.

Suggest an answer

Log in or Sign up to answer