How to store JSON data on Strung field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 03:28 AM
Hi All,
I have a requirement where I need to get the HR service JSON data and store in a HR case table field.
I created a new field "Processing Hidden" on HR case form of "String" Type. Now I need to get the json data of some fields of current HR case - HR Service and populate that json data into "Processing Hidden" field. How can I acheive this.?
I used something like this below:
var currentval = current.hr_service.getRefRecord(); // This will store HR service record object
gs.addInfoMessage("Alert current message" + " " + currentval);
current.u_processing_unit_time_hidden = currentval;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 03:45 AM
Not sure I understand your requirement 100%, but it sounds like all you need to do is to add JSON.stringify: current.u_processing_unit_time_hidden = JSON.stringify(currentval);
Best regards,
Sebastian Laursen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 03:54 AM
Try this
var currentval = current.hr_service.getRefRecord(); // This will store HR service record object
gs.addInfoMessage("Alert current message" + " " + currentval);
current.u_processing_unit_time_hidden = JSON.stringify(currentval);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 06:39 AM
Hi @Parul Sahu ,
You could stringify the JSON and store it in a text field. Then retrieve and parse the stored JSON text when you need to work with the actual JSON object.
The ServiceNow JSON API is documented here.
If you must store the hierarchy you'd need to design a table structure that represents a hierarchy of name-value pairs. You'd have to transform the JSON into appropriate records.