I need to create a .txt file on click of a scheduled job,can anyone help on this

Mohammed Hyder2
Kilo Expert

Hi All,

i Have to write a scheduled job which will create a .txt file and attach on the incident record

 

for example

var a = "test1";

var b = "test2";

once i click on execute its should create a .txt file with the above variables and save it on the incident record..

 

 

14 REPLIES 14

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Mohammed,

You may find  below thread helpful.

var attachment = new Attachment();
//attachment.write('TablenameFileToAttach','SysIDOfRecord','Filename','TypeOffile','ContentOfFile')
var attachmentRec = attachment.write('sc_req_item', '19647519db940010343688094896193b', 'TextFile'+".txt", "text", "Test file attached");

https://community.servicenow.com/community?id=community_question&sys_id=2e565161db1048105ed4a851ca96...

 

- Pradeep Sharma

Hi Pradeep,

Basically i need to query all the RITM's that were created today on a specific catalog item, Create a .txt file with all the details of the RITM and save that file on a existing incident..

 

for testing now, i will store hardcode 2 variables and i need to create a text file and save that file on a existing incident 

Thanks for the update Mohammed. Could you please try with the code shared? i.e query RITM with  catalog item and store those variables in one variable and then call Attachment(); to create a text file.

 

- Pradeep Sharma

Hi Pradeep,

I tried the below

 

var attachment = new Attachment();
var a = "hi";

var attachmentRec = attachment.write('incident', 'a1d58956db2094107f62264cd39619e7', 'Test123'+".txt", "text", "' +a + '");

 

but its not printing the the value stored in the variable a