- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2020 05:05 PM
Hi all,
I've got a requirement to automatically create and attach a JSON file to a RITM when a specific catalog item is submitted. The JSON file needs to have the variables and their values. Is this possible? I'm thinking maybe it can be done with GlideRecord to create the attachment and attach to the RITM, but not sure how to populate the JSON file with the variable names and values. Any thoughts? thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2020 06:18 PM
Do you have lot of variables that you want to add? If you have few then you can manually push them and save it as Allen recommended.
If you are doing this in run script then you can do something like
var payload = {};
payload.number = current.getValue('number');
payload.short_description = current.getValue('short_description');
var attachment = new GlideSysAttachment();
attachment.write(current, 'payload.json', 'text/plain', JSON.stringify(payload));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2020 07:49 PM
So I was able to achieve the goal with this script, perhaps not as elegant as Mike's suggestion so I'll play with that some more, but this script created the ".txt" file I needed and attached it to the RITM with the results as shown in the screenshot.
//JSON payload TEST
var myString = {"description":"'+current.variables.description+'","requested_for_2":"'+current.variables.requested_for_2.getDisplayValue()+'"}';
var ritmSysID = current.sys_id;
var gr = new GlideRecord('sc_req_item');
gr.get(ritmSysID);
var attach = new GlideSysAttachment();
attach.write(gr, 'payload.txt', 'text/plain', myString);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2020 05:55 AM
Patrick,
For the sake of any new readers, please just go ahead and mark Mike's reply as Correct. I have no problem with that.
You and I seem to keep having a disconnect where I say what I gave you was an example and it was up to you to figure it out from there and then you're replying back saying "I don't understand...isn't gr.getValue('field_name') a table column....I need variables"...
...and in Mike's he gave you everything you needed. So since you continue to reference his post more, just mark his Correct so that future readers will understand things better for this thread.
I'll try to remember your name and if I assist in the future I'll do better to give "exact" code you need, but I was under the impression that you would get the idea and be able to take it from there.
My example is "elegant" as well...there's just multiple ways it can be done. Period.
Sorry about that!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2020 07:26 AM
Hi Allen, thanks for all your help, and I'll do that...sorry if I confused things. and yes, your solution is elegant too! 🙂