Forums

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

Getting Last Comments data

Kumar, G Sunil March 19, 2023

Hello,

 

I am trying to get the last comment data from the issues which I am able to. But if there is no comment then I am getting null error. Is there a way to put in a default value if it is empty?

 

Regards,

Sunil

1 answer

1 accepted

1 vote
Answer accepted
Alex Koxaras -Relational-
Community Champion
March 19, 2023

Hi @Kumar, G Sunil 

I would use and if/else statement or the elvis operator. If e.g. you have something like the only below:

def comment = commentManager.getLastComment (issue)

comment.body

 

Then you could write:

if (comment.body == null) {

DEFAULT VALUE HERE

} else { comment.body }

OR

comment.body==null?DEFAULTVALUE_GOESHERE:comment.body

 

Kumar, G Sunil March 20, 2023

Hi Alex,

 

I am getting an error that .body cannot run on null value.

 

Regards,

Sunil

Alex Koxaras -Relational-
Community Champion
March 20, 2023

Type comment?.body instead

Kumar, G Sunil March 20, 2023

Hi Alex,

 

That worked.

 

Thank You

Alex Koxaras -Relational-
Community Champion
March 20, 2023

Kindly mark my answer as accepted in order to help others in the community with the same questions. Thank you!

Suggest an answer

Log in or Sign up to answer