how to create attachment excel record in servicenow using script

AnimeshP_96
Tera Guru

hello, 

Urgent help need

I have a updated excel that i want to attach to attachment record using script because kb article is published.

 

var attachment = new GlideSysAttachment();

//set up inputs
var rec = new GlideRecord('kb_knowledge');
rec.get('sys_id');
var fileName = 'abc.xls';
var contentType = 'application/vnd.ms-excel';
var content = '';

var agr = attachment.write(rec, fileName, contentType,content);

gs.info('The attachment sys_id is: ' + agr);


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh
2 REPLIES 2

Sid_Takali
Kilo Patron
Kilo Patron
var attachment = new GlideSysAttachment();
var rec = new GlideRecord('kb_knowledge');
rec.get('sys_id_of_the_kb_article'); 
var fileName = 'abc.xls';
var contentType = 'application/vnd.ms-excel';
var content = ''; 
var attachmentSysId = attachment.write(rec, fileName, contentType, content);
gs.info('The attachment sys_id is: ' + attachmentSysId);

?
i think you copy pasted my code, this is not working.!!
this code is already tried by me


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh