Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script runner custom field contains errors

Chiara Squilloni
Contributor
July 3, 2018

Hi everybody,

I have a custom field used by an internal plugin.

These lovely custom field is a scripted custom field.

In some operation these custom filed gets errors, in log I found:

[innovalog.jmcf.fields.CalculatedTextField] CalculatedTextField: error evaluating formula of field "Commenti" of issue XXXXX:
Sourced file: inline evaluation of: ``   import com.atlassian.jira.issue.comments.CommentManager;  import org.joda.tim . . . '' : Typed variable declaration : at Line: 12 : in file: inline evaluation of: ``   import com.atlassian.jira.issue.comments.CommentManager;  import org.joda.tim . . . '' : c .getCreated ( )

Target exception: java.lang.NullPointerException: Null Pointer in Method Invocation

 

The script is:

<!-- @@Formula:
import com.atlassian.jira.issue.comments.CommentManager;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormat;
import com.atlassian.jira.issue.comments.Comment;

StringBuilder s = new StringBuilder();
CommentManager commentManager = com.atlassian.jira.ComponentManager.getComponent(CommentManager.class);

Comment c = commentManager.getLastComment(issueObject);
DateTime datetime = new DateTime(c.getCreated().getTime());
DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/yyyy");
s.append(dtf.print(datetime));
s.append(" ");
s.append(c.getAuthorFullName());
s.append(" scrive: ");
s.append(System.lineSeparator());
s.append(c.getBody());
s.append(System.lineSeparator());

return s.toString();
-->

 

I didnt know how to fix it. Can anyone help me?

1 answer

0 votes
Alexey Matveev
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.
July 3, 2018

Hello, 

I guess the problem is that the c variable is null, if there are no comments and that is why you have the error. Try to write like this:

<!-- @@Formula:
import com.atlassian.jira.issue.comments.CommentManager;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormat;
import com.atlassian.jira.issue.comments.Comment;

StringBuilder s = new StringBuilder();
CommentManager commentManager = com.atlassian.jira.ComponentManager.getComponent(CommentManager.class);

Comment c = commentManager.getLastComment(issueObject);
DateTime datetime = new DateTime(c?.getCreated().getTime());
DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/yyyy");
s.append(dtf?.print(datetime));
s.append(" ");
s.append(c?.getAuthorFullName());
s.append(" scrive: ");
s.append(System.lineSeparator());
s.append(c?.getBody());
s.append(System.lineSeparator());

return s.toString();
-->

 

Chiara Squilloni
Contributor
July 4, 2018

Hi Alexey,

thank you so much for your reply. I try this and let you know.

 

Chiara

Chiara Squilloni
Contributor
July 4, 2018

Alexy I tryed this but unfortunaly these didn't work. I analyzed the issues in wich we have the problem and there are issues with almost a comment.

Suggest an answer

Log in or Sign up to answer