- 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:48 PM
I updated your script
var payload = {};
payload.description = current.variables.description.toString();
payload.requested_for_2 = current.variables.requested_for_2.toString();
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:52 PM
cool Mike, I'll try that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2020 07:54 PM
Hi Mike,
I see that it does create the ".json" file, however I don't seem to be able to open it to check the payload...is there a trick to that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2020 07:56 PM
I open it in notepad or TextEdit and verify the payload.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2020 08:05 PM
Yep, sorry I was able to open with a right click "Edit with Notepad". Perfect...thanks!
I actually changed this line to get the user's name:
payload.requested_for_2 = current.variables.requested_for_2.getDisplayValue();