How to display beautified JSON in an field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 04:11 AM
Hi all,
I am getting the below response from a GET method:
It needs to be updated in a string field (custom field created for this). But it should be updated with correct formatting as below:
Can anyone suggest me a solution for this?
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2022 03:22 AM
When I try to do it in Background Script, I could get the expected format in Log, but when I am trying to populate it with the string field, I am not able to do it:
Code in Background Script:
var initial_string = "{\"requested_items\":[{\"custom_fields\":{\"employee_name\":\"TEST Employee 3\",\"job_title\":\"Test Title 3\",\"manager\":19002284765,\"department\":\"CSO (101)\",\"employee_needs_an_access_badge\":false,\"new_badge_or_replacement\":\"New\",\"access_level_1_5\":\"2: Office/Lab\",\"employee_has_car\":false,\"license_plate_number_with_state\":\"MA XAS 54\",\"start_date\":\"2022-10-27\",\"end_date_for_non_permanent_staff\":\"2022-10-31\",\"notes\":\"test Request. please ignore\"},\"id\":19001155395,\"created_at\":\"2022-10-06T09:44:13Z\",\"updated_at\":\"2022-10-06T09:44:13Z\",\"quantity\":1,\"stage\":1,\"loaned\":false,\"cost_per_request\":0.0,\"remarks\":null,\"delivery_time\":null,\"is_parent\":true,\"service_item_id\":18}]}";
var json_object = JSON.parse(initial_string); // parse string to json object
var json_string = JSON.stringify(json_object, null, 4); // convert json object to string
gs.info(json_string);
Log Output:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2022 09:07 AM
When I give the string value statically in background script, target field is getting updated with desired JSON format
Code in Background script:
Target field in Incident form:
BUT, We cannot give the values like this statically, instead we have to stringify the response body & do the further steps, which indeed isn't giving the desired format
please find it below:
Code in Background script:
Target field in Incident form:
Please say what can be done?
TIA
