Is it possible to create and attach a JSON file to a RITM in server side scripting?

patricklatella
Mega Sage

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!

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

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));

View solution in original post

22 REPLIES 22

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));

cool Mike, I'll try that.

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?

I open it in notepad or TextEdit and verify the payload.

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();