Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Jira endpoints makes issues or some other issues for POST method

Amandeep39
Tera Contributor

Hello Everyone, I need a small help. I am trying to establish bidirectional(in&out) communication using two differnt ways. all are use basic auth which I tested works fine 

 

Example 1 - define restmessage for get and post the incidents on Jira board.

Get is working good I test on relted link ist works fine and 200 messge with all json format data came their
get endpoint is(https://<email>.atlassian.net/rest/api/3/search/jql?jql=project=SBIP&fields=*all) (basic auth tested here fine)

post endpoint is (https://<email>.atlassian.net/rest/api/3/issue)

please let me know POST endpoint is correct way or someother way we can figure it out?

 

I used the scheduled script, which does not work :- 

var request = new sn_ws.RESTMessageV2('JiraIssuesFetch','FetchIssueGETMethod');
var repsonse = request.execute();
var parseData = JSON.parse(repsonse.getBody());
gs.info("pasrsedata:" + parseData);
var loopCount = parseData.total - 1;
for (i = 0; i <= loopCount; i++) {
    var grIncident = new GlideRecords('incident');
    grIncident.addQuery('u_external_number', parseData.issues[i].key);
    grIncident.query();
    if (!grIncident.next()) {
        var grIncidentcreate = new GlideRecord('incident');
        grIncidentcreate.initialize();
        grIncidentcreate.short_description = parseData.issues[i].feilds.summary;
        grIncidentcreate.u_external_number = parseData.issues[i].key;
        grIncidentcreate.insert();
    }
}

 

from Jira to SN get the story value in incident table which will create or update using BR but not work their code is below: Async insert+update

(function executeRule(current, previous /*null when async*/ ) {
    gs.info("value of External_number", current.u_external_number);

    if (!current.u_external_number) {
        gs.info('external feild is null so create in a Jira ');

        var body = {
            "feilds": {
                "issuetype": {
                    "name": "Bug"
                },
                "project": {
                    "key": "SBIP"
                },
                "summary": current.short_description.getDisplayValue(),
                "description": {
                    "version": 1,
                    "type": "doc",
                    "content": [{
                        "type": "paragraph",
                        "content": [{
                            "type": "text",
                            "text": current.description.getDisplayValue()
                        }]
                    }]
                }
            }
        };

        var createGroup = new sn_ws.RESTMessageV2('Jira Issues create', 'Create issue  using Post');
        createGroup.setRequestBody(JSON.stringify(body));
        var response = createGroup.execute();
        gs.info("Jira issue creation response" + response.getBody());
    } else {
        gs.info("external number is not null ");
    }
})(current, previous);

 

Example 2. In post to Jira and SN' rm_story table using code instead of rest message still find problems

BR code here:Async and insert

(function executeRule(current, previous /*null when async*/ ) {
    var body = "{\"fields\":{\"project\":{\"key\":\"SBIP\"},\"summary\": \"Demo jira summary.\",\"issuetype\":{\"name\":\"Story\"}}}";
    gs.log("2nd stage of br");
    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint('https://<emailid>.atlassian.net/rest/api/3/issue');
    request.setHttpMethod('POST');
    request.setRequestBody(body);
    gs.log("3rd stage of br");

    var user = '<emailid>';
    var password = 'API key';
    gs.log("4th stage of br");

    request.setBasicAuth(user,password);
    request.setRequestHeader("Accept","application/json");
    request.setRequestHeader("Content-Type","application/json");

    var response =request.execute();
    gs.log("last stage of br" + response.getBody());
})(current, previous);
 
Schedule script for post it to Jira code is here:
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://<emailid>.atlassian.net/rest/api/3/search/jql?jql=project=SBIP&fields=*all');
request.setHttpMethod('GET');
gs.log("1st stage of SSE");

var user = '<emailid>@gmail.com';
var password = 'api key';
gs.log("3th stage of SSE");
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
var response = request.execute();
var parseData = JSON.parse(response.getBody());
var loop = parseData.total - 1;
gs.log("4th stage of SSE");
for (i = 0; i <= loop; i++) {
    var grstory = new GlideRecord('rm_story');
    grstory.addQuery('x_966447_intg_external_number', parseData.issues[i].key);
    grstory.query();
    if (!grstory.next()) {
        var grStoryCreate = new GlideRecord('rm_story');
        grStoryCreate.initialize();
        grStoryCreate.short_description = parseData.issues[i].fields.summary;
        grStoryCreate.x_966447_intg_external_number = parseData.issues[i].key;
        grStoryCreate.insert();
    }

}
gs.log(response.getBody());

Can anyone help me in both examples, which is bidirectional communication
#integration
0 REPLIES 0