The CreatorCon Call for Content is officially open! Get started here.

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 

3 ACCEPTED SOLUTIONS

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/

View solution in original post

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

 

 

 

 

 

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@AbdurRahmanSnow 

I created blog for this for generating CSV from RITM variables and attach to record, you can refer the same and enhance it for json format and include that in text file

Generate csv file with the catalog variables and attaching to RITM record 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Glad !!

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

 

 

 

 

 

Thank you so much @Brad Bowman  . Really appreciate your knowledge.

Ankur Bawiskar
Tera Patron
Tera Patron

@AbdurRahmanSnow 

I created blog for this for generating CSV from RITM variables and attach to record, you can refer the same and enhance it for json format and include that in text file

Generate csv file with the catalog variables and attaching to RITM record 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@AbdurRahmanSnow 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader