output from fix script to a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 06:23 AM
Is it possible to output gs.print to a log file from a fix script or scheduled job?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 09:28 AM
No, this is not possible. and even if it would be, you would not be able to get to that file
What I usually do in such case is one of the following:
a) write to log table using gs.log, gs.info etc.
b) You can create a file and attach it to a record - i tend to use my user record for such things See example below
// array to collect what needs to be stored in file
var updated_records = [];
// loop here on your content and store what you need in array...
// can even use GlideRecords as XML if you want
{
var xml = new GlideRecordXMLSerializer();
updated_records.push(xml.serialize(gr_data));
}
// now store to user record
var gr_user = new GlideRecord('sys_user');
gr_user.get('user_name', '<user_name>');
var ga = new GlideSysAttachment();
ga.write(gr_user, 'myfile.json', 'text', JSON(updated_records));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2021 09:42 AM
When I try this, I get the error on the ga.write line of:
'JSON' is not a function
When I changed the line to:
ga.write(gr_user, 'myfile.json', 'text', JSON.stringify(updated_records));
it worked.
Thanks for the tip! I've been looking for a workaround for a year!