How to update Number Custom Field value in Workflow Post Function

Hi

 

I am trying to create Workflow with the PostFunction in one of the steps to update one of the Number Custom Fields and getting error.

 

Looked everywhere ...

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager       = ComponentAccessor.getIssueManager()

Issue issue  = issue

def cfRevisionMinor    = customFieldManager.getCustomFieldObjectByName("Revision (Minor)") 
def cfErrataRevisionMinorVal = issue.getCustomFieldValue(cfErrataRevisionMinor)

issue.setCustomFieldValue(cfErrataRevisionMinor, cfErrataRevisionMinorVal.toString() + 1 )

 

Not sure what I am doing wrong ...

 

Thanks,

Areg

1 answer

1 accepted

This widget could not be displayed.

Not sure why you are using toString there... "1"  + 1 doesn't make much sense.

Otherwise seems OK.

 

 

Hi Jamie

 

When I am trying without toString inline compiler giving me error for "+ 1" ...

Not sure why.

I will share screen shot on Monday.

 

Regards,

Areg

 

Hi

Not sure what is wrong ..

2016-02-15 10:26:24,928 ajp-nio-8600-exec-10 ERROR username 626x557131x1 1jbpz3k 10.1.135.157 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: ISSUE-1, actionId: 11, file: <inline script>
java.lang.NullPointerException
        at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:1095)
        at com.atlassian.jira.issue.Issue$getCustomFieldValue$7.call(Unknown Source)
        at Script266.run(Script266.groovy:13)

 

Error.jpg

Regards,

Areg

Hi Areg,

I can see two different issues. The first one is that you get a NullPointerException. Is the script you pasted in your original question the whole script ? If yes then in the lines 

def cfRevisionMinor = customFieldManager.getCustomFieldObjectByName("Revision (Minor)")
def cfErrataRevisionMinorVal = issue.getCustomFieldValue(cfErrataRevisionMinor) <-- should it be cfRevisionMinor ?

The second issue is in the screenshot you pasted, which is a static type checking where in some cases is safe to ignore. In your case you can correct it if type casting the 

cfErrataRevisionMinorVal as Double

Hi Thanos

 

Sorry for confusion - I was trying to do some tidy up and messed up in my question.

Here is the full code:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager       = ComponentAccessor.getIssueManager()

Issue issue  = issue

def cfErrataRevisionMinor    = customFieldManager.getCustomFieldObjectByName("Errata Revision (Minor)") 
def cfErrataRevisionMinorVal = issue.getCustomFieldValue(cfErrataRevisionMinor) as Double

issue.setCustomFieldValue(cfErrataRevisionMinor, cfErrataRevisionMinorVal + 1 )

 

Found NPE source - messed up with the Names - my bad.

 

All working now!

 

Regards,

Areg

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

534 views 3 19
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