- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 07:48 PM - edited 05-19-2023 07:57 PM
In the string below, I want to pull only the values (in bold) for assets_assigned_to_submitted_for.
"[{\"tb_submitted_for\":\"4cfb00b0c3d599d07ee3251ce0013178\",\"state_submitted_for\":\"In use\",\"assets_assigned_to_submitted_for\":\"b142f66d374843809bfbdaa543990ea2\"},
{\"tb_submitted_for\":\"4cfb00b0c3d599d07ee3251ce0013178\",\"state_submitted_for\":\"Review\",\"assets_assigned_to_submitted_for\":\"6c2bd5851b640c90e7d6620f6e4bcb5c\"},
{\"tb_submitted_for\":\"4cfb00b0c3d599d07ee3251ce0013178\",\"state_submitted_for\":\"Review\",\"assets_assigned_to_submitted_for\":\"3c4d400a372243046b75d5c543990ee1\"}]"
The number of rows will vary...
The solution is for a client script.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 06:07 AM
@Lon Landry4 Please update your script as follows.
function onSubmit() {
//Type appropriate comment here, and begin script below
var assetsIcertify = g_form.getValue('u_returning_asset_submitted_for');
var assetsIcert = JSON.parse(assetsIcertify);
var submitted_for1 = assetsIcert[0].assets_assigned_to_submitted_for; //will give you sys_id of assigned_to
g_form.setValue('certification_results',submitted_for1);
return;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 08:01 PM
@Lon Landry4 use JSON.parse(stringJSON); to convert string to an object and access the individual property by dot walking for e.g.
var answer = '{"first_name":"John"}';
answer= JSON.parse(answer);
var firstName = answer.first_name;
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 08:28 PM
I tried in my script.
But, var firstName = answer.first_name;
results in John (or in my case the sys_id) mentioned in script as opposed to a value from string.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 09:28 PM
In your case you can access the attributes as follows.
var submitted_for = answer[0].tb_submitted_for; //will give you sys_id of submitted for
var state = answer[0].state_submitted_for; //value of state
var submitted_for = answer[0].assets_assigned_to_submitted_for; //will give you sys_id of assigned_to
You can also use a for loop to access these values one by one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 09:57 PM - edited 05-19-2023 10:07 PM
Error while running Client Script "set certification_results": TypeError: Cannot read properties of undefined (reading 'assets_assigned_to_submitted_for')