How to update Number Custom Field value in Workflow Post Function

Areg Vrtanesyan _Work_ February 12, 2016

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

1 vote
Answer accepted
JamieA
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.
February 12, 2016

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

Otherwise seems OK.

 

 

Areg Vrtanesyan _Work_ February 12, 2016

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

 

Areg Vrtanesyan _Work_ February 14, 2016

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

Thanos Batagiannis _Adaptavist_
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.
February 15, 2016

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
Areg Vrtanesyan _Work_ February 15, 2016

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
TAGS
AUG Leaders

Atlassian Community Events