Whenever Catalog Form is submitted, it's variable data should get converted into JSON format and....

AbdurRahmanSnow
Giga Guru

Whenever a Catalog Form is submitted, it's variable data should get converted into JSON format and get attached to the RITM ticket.
How is it possible? Please help.
@Ankur Bawiskar @Dr Atul G- LNG @Viraj Hudlikar 

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Sorry mate, no idea on this.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

No problem Sir. Thank you for your reply.

kaushal_snow
Mega Sage

Hi @AbdurRahmanSnow ,

 

Yes, you can convert the submitted catalog variables into JSON and attach that JSON to the RITM. I’ve done something similar before in my instance; here’s how you can do it...

 

>> Create a Business Rule (or Flow) that runs after insert on sc_req_item (or your RITM table).

>> In the script, access current.variables to get all variable names & values.

>> Build a JSON object from those values, using .getDisplayValue() where needed for reference/choice fields. Serialize via JSON.stringify(...).

>> Use GlideSysAttachment to write that JSON string to a file (e.g.variables.json) and attach it to the RITM record.

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Brad Bowman
Kilo Patron
Kilo Patron

Here's how I have done something similar with Flow Designer.  First you need to create a custom action that looks like this:

BradBowman_0-1758049873565.png

for Content type, create choice values like you see in your sys_attachment table - text/plain, application/json;charset=UTF-8, image/jpeg... This custom action is generic enough to be re-usable any time you need to create an attachment.

 

The Script step also needs inputs created, mapped from the Action inputs, and the Script

BradBowman_1-1758050043307.png

(function execute(inputs, outputs) {
    var attach = new GlideSysAttachment();
    var rec = new GlideRecord(inputs.tableName);
    rec.get(inputs.recordSysID);
    var fileName = inputs.fileName;
    var contentType = inputs.contentType;
    var content = inputs.content;
    var agr = attach.write(rec, fileName, contentType, content);
    outputs.attachment = agr;
})(inputs, outputs);

and an output in the Script step

BradBowman_2-1758050165515.png

and finally an Action output mapped from the script step output

BradBowman_3-1758050214476.png

My Flow looks like this when calling the custom action

BradBowman_4-1758050297420.png

The Content script:

var variablesGR = new GlideRecord('sc_req_item');
variablesGR.get('sys_id', fd_data.trigger.request_item.sys_id);
return JSON.stringify(new GlideRecordToObject().toObject(variablesGR.variable_pool));