The CreatorCon Call for Content is officially open! Get started here.

Jira to ServiceNow Integration

manju5
Tera Contributor

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.

manju5_0-1701427339941.png

 

Thanks,

Manju

9 REPLIES 9

I am passing like 

 

var att = request.body.data.fields.attachment;
var attLength = parseInt(att.length);

 

 

If you gs.log the value of attLength. If this is 2 then your loop will run twice and attach 2 times?

Ankur Bawiskar
Tera Patron
Tera Patron

@manju5 

it would be nice if you share script rather than image

what debugging have you done so far?

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

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

manju5
Tera Contributor

Hi,

 

Please could anyone help me ?

 

Thanks,

Manju