- 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-20-2023 04:03 AM
@Lon Landry4 Could you please post your script here in the thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 04:59 AM - edited 05-20-2023 06:03 AM
function onSubmit() {
var assetsIcertify = g_form.getValue('u_returning_asset_submitted_for');
g_form.setValue('certification_results',assetsIcertify);
return;
}
1. Script to test that data is present
above script returns (UPDATED)
[{"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"}]
So, the data I need is here...(I am testing in Service Portal)
2. new script results in error assets_assigned_to_submitted_for is undefined
function onSubmit() {
//Type appropriate comment here, and begin script below
var assetsIcertify = g_form.getValue('u_returning_asset_submitted_for');
const assetsIcert = JSON.stringify(assetsIcertify)
var answer = {"assets_assigned_to_submitted_for":"b142f66d374843809bfbdaa543990ea2"}
var submitted_for1 = answer[0].assets_assigned_to_submitted_for; //will give you sys_id of assigned_to
g_form.setValue('certification_results',submitted_for1);
return;
}
---end of script---
I have tried regex, sessionStorage, and 154 script possibilities.

- 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-20-2023 06:23 AM
Thanks for your help in time with this. I will mark it correct as soon as I work out the looping.
I can return the number of rows, so I must be close...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2023 07:17 AM - edited 05-20-2023 07:21 AM
Any idea why this loop does not work?
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
var i = 0;
var done = false;
while(!done){
if (i >= 1){
++i;
g_form.setValue('certification_results',submitted_for1);
continue;
}
done=true;
return;
}}