Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner not able to get last comment into string and perform comparision

Hi all,

I am trying to get the last comment and check if that contains a string. If string found transition the issue.

Trying to do this via scriptrunner. Have created the below script and added it to the listener. But am getting into the "null" pointer exception.


Interestingly, when am returning "comment.body" this is working fine but when storing in a string, it is not getting stored and not able to perform any string operations on it.

Example last comment on JIRA ticket:  Ram has updated the status of a ticket linked to this issue from [Open] to [Resolved]  


Based on this comment ticket will need to be moved to Resolved (transition id :11)

Your quick help is much appreciated.

 

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor


def issueService = ComponentAccessor.getIssueService()
IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject("ITP-26")
def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment (issue)

//return comment.body is printing the last comment properly
// if i use println(comment.body) - getting null value.

String lastcomment = comment.getBody()
// this is the last comment on the ticket: Ram has updated the status of a ticket linked to this issue from [Open] to [Resolved]

lastcomment.contains("has updated the status of a ticket linked to this issue from [Open] to [Resolved]")
// is returning false

// when trying to put in if condition getting null
// if(lastcomment.contains("has updated the status of a ticket linked to this issue from [Open] to [Resolved]"))

 

 



Regards,
Ram

1 answer

0 votes
Ravi Sagar Community Leader May 17, 2021

Hi @newstart Newstart 

What exactly is here in the null pointer exception error, maybe paste your error as well.

Null pointer exception means that you are trying to call a method on a null object. So let us say your issue has no comment then you cannot call comment.body hence the error.

Add some error handling in your code to check those cases.

Ravi

Hi Ravi,

Thanks for your quick response.

def comment = commentManager.getLastComment (issue)

return comment.body  --- this is returning last comment.

However, when trying to store the last comment in a string and perform string operations it is not working

Screenshot 2021-05-17 at 5.24.29 PM.png

 

String lastcomment = comment.body
// this is the last comment on the ticket: Ram has updated the status of a ticket linked to this issue from [Open] to [Resolved]
println(lastcomment)
if (lastcomment.contains("has updated the status of a ticket linked to this issue from [Open] to [Resolved]"))
println("Matching Found")

else
println("Matching Not Found")

 

 

Screenshot 2021-05-17 at 5.27.23 PM.png

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

280 views 8 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you