ServiceNow to Jira integration Scheduled jobs script fail

hanimi9623
Tera Expert

Requirement:
Fetch the projects list from Jira to ServiceNow. In ServiceNow created custom table(u_jira_project_details) with 2 custom fields, one is "u_project_id" (string) & another one is "u_project_manager" (string).

 

Created REST outbound message successfully connected with Jira.

HTTP Method: GET
End point: https://.........atlassian.net/rest/api/3/project


Authentication: Basic

Test results: 200(Success)


I didn't understand where is mistake from scheduled jobs. Please correct me if any mistakes find in script.

 

Scheduled jobs:

Active: True
Application: Global
Run: Daily


Javascript:

 

(function() {
var rm = new sn_ws.RESTMessageV2('Jira Projects', 'GET');
var response = rm.execute();
var status = response.getStatusCode();
gs.info("Jira API status code: " + status);

if (status != 200) {
gs.error("Jira API call failed. Status: " + status + ". Response: " + response.getBody());
return;
}
var responseBody = response.getBody();
var projects = JSON.parse(responseBody);

for (var i = 0; i < projects.length; i++) {
var project = projects[i];

var projectId = project.id;
var managerName = project.lead ? project.lead.displayName : 'Unknown';
var gr = new GlideRecord('u_jira_project_details');
gr.addQuery('u_project_id', projectId);
gr.query();

if (gr.next()) {
gr.u_project_manager_name = managerName;
gr.update();

} else {
gr.initialize();
gr.u_project_id = projectId;
gr.u_project_manager_name = managerName;
gr.insert();
}
}

})();

 

3 REPLIES 3

Anil Nemmikanti
Giga Guru

Hi @hanimi9623 ,

May I ask for the screen shot of the error message? as I couldn't see any issue with the code.

Ankur Bawiskar
Tera Patron
Tera Patron

@hanimi9623 

please share the error message

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

JavierPM
Tera Contributor

Hi @hanimi9623, I'm the community manager at Exalate.

 

It looks like you're close to completing your requirement. Your script and API call seem fine since you're getting a 200 response, but there may be a small issue with field names or how the response is structured.

One quick suggestion: double-check the field name in your table, it looks like you're using u_project_manager_name in the script, but only defined u_project_manager in your table. That mismatch would cause the script to fail silently at the update/insert step.

Also, consider logging project or project.lead to make sure the data is shaped as expected.

If this suggestion does not work, could you share the error message you received?

 

Good luck with this requirement!