post function script to fetch the latest comment with default message
Asked by Durgesh Masurkar:

I have applied one script in workflow post function, the use of script is to give me the latest comment.

I'm doling a transition from A status to B status, during this time I'm setting a default comment with post function custom script.

![image.png](/t5/image/serverpage/image-id/315118iCA83601A60433A41/image-size/large?v=v2&px=999 "image.png")

on the same transition I have comment screen as well:

![image.png](/t5/image/serverpage/image-id/315119i130A25D0FA2CD5AC/image-size/large?v=v2&px=999 "image.png")

Here my question is:

I am doing this transition A-\>B, if I'm not adding comment manually and directly doing the transition then the default comment is coming correctly.(Which is added in post function)

but what if I added a comment any message in the **Response to customer**section

it should give me "my manually added message/comment" + "default/static comment message"

here I'm getting my previous last comment(which was exactly added before performing the transition), **but it is not giving me the last comment which I have added on the transition screen + Default/static message ? Why?**

**In very short- I need manually added message/comment + default/static comment??**

Anyone's help regarding this matter would be really appreciated.


Answers:
author: Kseniia Trushnikova
body: Hi [@Durgesh Masurkar](/t5/user/viewprofilepage/user-id/5249344),

I don't use Scriptrunner but I use JMWE and I guess this may work for you too. Correct me please if I misunderstood your question.

If you want to add two comments into one, you can transform a *transition* comment by adding this script **above** the system post function "Add a comment to an issue if one is entered during a transition":

```
//Get a transition comment
def originalTransientVarsComment = transientVars.comment ?: ""

//Define the default comment
def defaultComment = "This is a default comment."

//Check if a comment has been added on the transition screen, then update it
if (transientVars.comment) {
transientVars.comment = originalTransientVarsComment + "\n\n" + defaultComment
} else {
transientVars.comment = defaultComment
}
```

* If no comments were added during the transition, only the default comment will be added to the ticket.
* If a transition comment is present, it and the default comment will be added to the ticket as one comment.

Here's the example. I added a comment during the transition and this is what was added to my ticket:

![Screenshot 2024-03-29 at 23.07.08.png](https://community.atlassian.com/t5/image/serverpage/image-id/315385i1726032B7FDEDA02/image-size/large?v=v2&px=999 "Screenshot 2024-03-29 at 23.07.08.png")

comments: author: Durgesh Masurkar
body: Hi [@Kseniia Trushnikova](/t5/user/viewprofilepage/user-id/4593830) ,

Thanks for sharing the details, I'll check and update you regarding this.

Thank you for your support!!!


author: Kseniia Trushnikova
body: Hey [@Durgesh Masurkar](/t5/user/viewprofilepage/user-id/5249344), did it work?


author: Durgesh Masurkar
body: Dear [@Kseniia Trushnikova](/t5/user/viewprofilepage/user-id/4593830) ,

Thanks for support!


Tags: jira-service-desk-data-center

jira-service-management

jira-service-management-data-center

jira-service-management-server

server