Jira to ServiceNow Integration using REST API and Webhook

Maareeswari R1
Tera Contributor

I'm Integrating ServiceNow and Jira using ServiceNow REST API. But when i try to push data's from JIRA to ServiceNow ,Jira data's are not updating in ServiceNow. From Jira side we have created Webhook and ServiceNow side we have created scripted REST API.

Here I'll share the Scripted rest api code:

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    try {
        // Extracting data from the request
        var requestBody = request.body.data;
 
        // Logging for debugging purposes
        gs.log('Jira Log: ' + JSON.stringify(requestBody));
 
        // Creating or updating records in the 'u_jira_stage' table
        var jr = new GlideRecord('u_jira_stage');
        jr.addQuery('u_issue_id', requestBody.issue.id);
        jr.addQuery('u_project_key', requestBody.issue.fields.project.key);
        jr.query();
gs.log("query"+jr);
 
        if (!jr.next()) {
            // If the record doesn't exist, create a new one
            jr.initialize();
            jr.u_project_name = requestBody.issue.fields.project.name;
            jr.u_project_key = requestBody.issue.fields.project.key;
            jr.u_issue_id = requestBody.issue.id;
            jr.u_issue_key = requestBody.issue.key;
            jr.u_summary = requestBody.issue.fields.summary;
            jr.u_description = requestBody.issue.fields.description;
            jr.insert();
            gs.log('Jira Issue created: ' + jr.u_issue_id);
        } else {
            // If the record exists, update it
            jr.u_summary = requestBody.issue.fields.summary;
            jr.u_description = requestBody.issue.fields.description;
            jr.update();
            gs.log('Jira Issue updated: ' + jr.u_issue_id);
        }
    } catch (ex) {
        // Handle exceptions and log details
        gs.error('Error processing Jira request: ' + ex.message);
        response.setStatus(500); // Set HTTP status code to 500 for internal server error
        response.setBody({ error: ex.message() });
    }
})(request, response);

 

0 REPLIES 0