Using a ScriptRunner Clone Issue Post Function, how can I set a comment on the cloned issue?

Bert Dombrecht
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.
January 11, 2022

On Jira Software Cloud, I'm using the ScriptRunner Clone Issue Post Function to create a child issue automatically.

In the 'Additional Code' section I can update some fields for the cloned issue, for example:

issueInput.fields.summary = "Prefix " + issueInput.fields.summary;

However, I cannot seem to set a comment on the to-be-created cloned issue.

On Server, this was done as:

 

doAfterCreate = {
// Add Comment
    // dispatch an event after creating the comment
    final boolean dispatchEvent = true
    // the body of the comment
    final String commentBody = "Auto-generated Issue"
    // the author of the comment will be the logged in user
    def author = ComponentAccessor.jiraAuthenticationContext.loggedInUser
 
    ComponentAccessor.commentManager.create(issue, author, commentBody, dispatchEvent)
 
// Update Issue   
    issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
What is the way to do this in ScriptRunner for Jira Cloud?
I appreciate your help!

1 answer

0 votes
Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2022

Hi @Bert Dombrecht 

 

Please check this docs:

https://community.atlassian.com/t5/Jira-Software-questions/Jira-Cloud-ScriptRunner-How-to-add-comments-to-issues-in/qaq-p/1258613

https://www.youtube.com/watch?v=9gppxfiEhxU

 

Both links are not exactly what you need but you can see an example how to add comment in Jira Cloud.

 

Regards,

Seba

Bert Dombrecht
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.
January 11, 2022

Hi @Sebastian Krzewiński 

Thanks for your reply.

The information you shared handles adding a comment to an already existing issue.
In that case I can indeed use post("/rest/api/3/issue/${issue.key}/comment")

However, the crux here is that I want to pass a comment to a issue that has not been created yet (during the Clone action), so there is no issue.key yet.

I was assuming I need to use issueInput.update somehow ...

Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2022

Ask Script runner support. Maybe they will have solution for that.

Dimitri Cools March 27, 2024

@Bert Dombrecht  ever got any further on this ? I 'm struggling with similar scenario

Bert Dombrecht
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.
March 27, 2024

I'm afraid not...

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events