Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

create attachment record in knowledge table using script for type excel

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

Bhavya11
Kilo Patron
Kilo Patron

hi @AnimeshP_96 ,

 

Please create Before update Business rule, and add the condition when Workflow changes to "Publish" then below script can be added

 

var attachment = new GlideSysAttachment();
var rec = new GlideRecord(current.sys_class_name);
rec.get(current.sys_id);
var fileName = 'example.txt';
var contentType = 'text/csv';
var content = 'The text that is stored inside my file';

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

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

 

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK

 

@Bhavya11 
i think you didnt get the context first you dont require a business rule for it because i just have to attach a file in the record., theni am working with excel data not csv, let me know if you have any other solutions for it.


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




Regards,
Animesh