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

Oke clear. How do you know which incident? You do mention an existing incident.

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

LinkedIn

Still any help needed? Or did you figure it out already?

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

LinkedIn

Hi there,

Did this solve your question? Or do we need to follow-up on this?

Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.

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

LinkedIn

Jaspal Singh
Mega Patron
Mega Patron

Hi Mohammed,

 

Not sure about your business requirement (why scheduled job) but this can be created as an attachment & attached to the RITM with filled variable details as & when a RITM is submitted.

Look for blog that you may find helpful. This though may require few tweaks but should give you an understanding of how to proceed.

asifnoor
Kilo Patron

Hello Hyder,

Here is a sample script, which you can try.

var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery("sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()"); //fetches ritms created on today
gr.query();
var contents="";
while(gr.next()) {
  contents = contents+gr.getValue("number"); //add more columsn whatever you want here
  contents = contents+"\n";
}

var filename = "ritms.txt";//your filename
var gr1 = new GlideRecord("incident");
gr1.get("ff4c21c4735123002728660c4cf6a758")//put your incident sys_id to which you want to attach
//create the attachment
var attachment = new GlideSysAttachment();
attachment.write(gr1,filename,"txt",contents);

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP