I need to create a .txt file on click of a scheduled job,can anyone help on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 01:11 AM
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..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 01:55 AM
Updated the script i.e You should just pass variable a value without +a.
var attachment = new Attachment();
var a = "hi";
var attachmentRec = attachment.write('incident', 'a1d58956db2094107f62264cd39619e7', 'Test123'+".txt", "text", a);
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 02:36 AM
Thanks Pradeep,
I will create a script which will query on the RITM table and i need to store all the values in the .txt file

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 02:55 AM
Sure.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 01:24 AM
Hi there,
Can you explain a bit more when this should happen and on which record? I mean you are mentioning a scheduled job, on click, on a incident? Which incident, a new one or an existing one? Scheduled job on click, so a manual scheduled job or do you perhaps mean a UI Action?
Setting up a scripted txt attachment itself isn't that though. For that you could use already something like below:
(function() {
var attachment = new Attachment();
//attachment.write('TablenameFileToAttach','SysIDOfRecord','Filename','TypeOffile','ContentOfFile')
var attachmentRec = attachment.write('incident', 'a7409cce2f689490b0c2d5ea2799b6f0', 'TextFile' + ".txt", "text", "Test file attached");
})();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 01:32 AM
Hi Mark,
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..