Update fields from ServiceNow to Jira

Shalika
Tera Expert

I have a Post message which creates an issue in Jira. Now, I want that whenever I update my incident record, then the issue that is created in Jira, should also be updated.

The content of the payload of POST message which I have is

{
    "fields": {
        "project": {
            "key": "SSP"
        },
        "issuetype": {
            "name": "Bug"
        },
        "description": {
            "type": "doc",
            "version": 1,
            "content": [{
                "type": "paragraph",
                "content": [{
                    "type": "text",
                    "text": "${description}"
                }]
            }]
        },
        "summary": "${summary}",
        "reporter": {
            "id": "${reporter}"
        },
         "priority" : {
"name": "${priority}"
},
 "attachment": [],
    "customfield_11207": "TBD",
        "customfield_11133": {
            "value": "TBD",
            "id": "10256"
        }

    }
}

The Business Rule which I have is - 

try{

        var sm = new sn_ws.RESTMessageV2('Neste Siili JIRA', 'POST');
        
        sm.setStringParameter("description",current.description);
        sm.setStringParameter("summary",current.number+'  '+current.short_description);
        sm.setStringParameter("reporter","614d5f6476e34d006984105b");
        sm.setStringParameterNoEscape('attachments', '');
     
    if(current.priority == "1")
            {
                sm.setStringParameter("priority","Critical");
            }
    if(current.priority == "2")
            {
                sm.setStringParameter("priority","Major");
            }
    if(current.priority == "3" || current.priority == "4")
            {
                sm.setStringParameter("priority","Minor");
            }
    var attachmentsJson = '';
                attachmentsJson += ' { "content_type":"' + current.content_type + '",';
                attachmentsJson += '"file_name":"' + JSUtil.escapeText(current.file_name) + '",';
                attachmentsJson += '"size_bytes":"' + current.size_bytes + '",';
                attachmentsJson += '"sys_id":"' + current.sys_id + '"';
                attachmentsJson += '}';

                sm.setStringParameterNoEscape('attachments', attachmentsJson);
         //gs.log("hello user"+current.opened_by);
        gs.log("hello INC Silli ");
 var response = sm.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
        gs.log("hello jira status"+ httpStatus);
    gs.log("hello JIRA response"+responseBody );    
}
catch(ex) {
 var message = ex.message;
}
 })(current, previous);

 

What should I do next for updating the record in Jira Issue?

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi

please follow the instructions on page https://developer.atlassian.com/server/jira/platform/updating-an-issue-via-the-jira-rest-apis-684860...

The most important thing: Updates have to be performed via PUT method. A POST method is only for creating issues.

Kind regards
Maik

I am getting error message as 

{"message":"null for uri: https://neste-jira.atlassian.net/rest/api/3/SSP","status-code":404}

when creating put method

Eric Smith
Tera Expert

Shalika, hello. Seems to me you need a two-way connection between the two, if not having one already. We use a tool to sync Jira and Snow, and keep the two up-to-date whenever there is a change. It connects the systems quite quickly and you do not have to worry about the code. Check it out, you might find it useful.

I cannot use a 3rd party tool to do the integration