Adding a comment that is stored in a smartvalue (Variable) as an ADF(Atlassian Document Format) using Automation

Still need help?

The Atlassian Community is here for you.

Ask the community


Summary

Adding a comment that is stored in a SmartValue (Variable) as an ADF(Atlassian Document Format) using Automation.

Environment

Jira Service Management

Diagnosis

ADF formatted JSON is added under the Variable name {{CommentBody}}

{ "body": { "content": [ { "type": "codeBlock", "attrs": {}, "content": [ { "type": "text", "text": "Hi Team,\n\nWe haven't heard back from you for 10 days, so we're automatically closing this support request for now.\n\nPlease feel free to re-open or comment on this issue if you still need help!\n\nBest Regards,\nAutomation for JIRA" } ] } ], "type": "doc", "version": 1 } }

(info) CommentBody is a variable setup in the Automation and is accessible as a smart-value using {{CommentBody }}

Further, the Advanced Field Function under Edit Issue action is used to add a comment on the Service Desk ticket during the Workflow transition. The comment body contains the value of the above-declared Variable {{CommentBody}}

{
    "update": {
        "comment": [
            {
                "add": {
                    "body": {{CommentBody}}   
                }
            }
        ]
    }
}


However, the variable {{CommentBody}} is stored with a Valid ADF Document, we get the following error in Automation:

Solution

While using the Edit Issue action in Automation, it's not possible to add comments using Variables with ADF formatted JSON script.

So the solution would be to use Send Web Request or API  to add comments using an ADF formatted JSON.

(lightbulb)To create an ADF(Atlassian Document Format) document, you can refer to this link.

  • Using the Send Web Request method

Issue Trigerred: Issue Transitioned

Issue Action: Created Variable for Issue Key {{issuekey}}

Issue Action: Send Web Request

Web request URL*: https://<site name>.atlassian.net/rest/api/3/issue/{{issuekey}}/comment

HTTP method*: POST

Web request body*: Custom data

Custom data*:


{ "body": {
    "content": [ 
        {
      "type": "codeBlock",
      "attrs": {},
      "content": [
        {
          "type": "text",
          "text": "Hi Team,\n\nWe haven't heard back from you for 10 days, so we're automatically closing this support request for now.\n\nPlease feel free to re-open or comment on this issue if you still need help!\n\nBest Regards,\nAutomation for JIRA"
        }
      ]
    }
    ],
    "type": "doc",
    "version": 1
             }
    }




  • Delay execution of subsequent rule actions until we've received a response for this web request

Headers (optional):   --header 'Accept: application/json' \

                                    --header 'Content-Type: application/json' \

                                    --Authorization: Basic "<EMAIL>:<API_TOKEN>" encoded to base64.

                E.g.: Authorization Basic HzxuhHbhzhdjasYTgdjGfrGHzxuhHbhzhdjasYTgdjGfrG

banner2.png

  • Using API

Method: POST

URL: https://<site name>.atlassian.net/rest/api/3/issue/{{issuekey}}/comment

Headers (optional):   --header 'Accept: application/json' \

                                    --header 'Content-Type: application/json' \

                                    --Authorization: Basic "<EMAIL> and <API_TOKEN>" 

Comment added to Jira ticket:




Last modified on May 1, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.