Jira to ServiceNow Integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 02:43 AM
Hi,
I am sending the attachment from Jira to ServiceNow, It's is working partially like when I add attachment in Jira it is updating but in ServiceNow it is attaching twice. I shared the code below please check the code and let me know where am I wrong.
Thanks,
Manju
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 03:45 AM
I am passing like
var att = request.body.data.fields.attachment;
var attLength = parseInt(att.length);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 03:46 AM
If you gs.log the value of attLength. If this is 2 then your loop will run twice and attach 2 times?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 05:18 AM
it would be nice if you share script rather than image
what debugging have you done so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2023 10:25 PM
Hi @Ankur,
I have shared code below. Please check the code and let me know .
var att = request.body.data.fields.attachment;
var attLength = parseInt(att.length);
var id = 0;
var filename;
for (var i = 0; i<attLength; i++) {
if (id == 0) {
id = att[i].id;
filename = att[i].filename;
attachment(id, filename);
} else if (id < att[i].id) {
id = att[i].id;
filename = att[i].filename;
attachment(id, filename);
}
}
function attachment(id, filename) {
try {
inc = new GlideRecord('incident');
inc.addQuery('u_jira', request.body.data.key);
inc.query();
if (inc.next()) {
inc.u_attachment_correlation_id = id;
inc.update();
var attachment = new sn_ws.RESTMessageV2('JIRA', 'Default GET');
attachment.setStringParameterNoEscape('id', id);
attachment.saveResponseBodyAsAttachment('incident', inc.sys_id, filename);
var response = attachment.execute();
var Status = response.getStatusCode();
if (Status != '200')
gs.log("Jira issue" + response.getErrorMessage());
else
gs.log('Jira issue: ' + filename);
}
} catch (ex) {
gs.log('ERROR in Jira ' + ex, true);
}
}
Thanks,
Manju
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 02:18 AM
Hi,
Please could anyone help me ?
Thanks,
Manju