Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

how to add attachment excel record in servicenow using script

AnimeshP_96
Kilo Sage

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
3 REPLIES 3

Ankur Bawiskar
Tera Patron

@AnimeshP_96 

you cannot create excel file and write it to record. you can create csv file

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

@Ankur Bawiskar 
thanks for the reply, but it was working with custom data in the excel and the excel was attached to the record, but the problem is that i am not able to read the data from the excel in snow, if that may be possible with decode /encode method no idea, 


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




Regards,
Animesh

@AnimeshP_96 

you want to read excel file?

if yes then you need to use GlideExcel parser

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