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

Get all variable values from a string in a client side script

Lon Landry4
Mega Sage

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.

1 ACCEPTED SOLUTION

@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;
}

View solution in original post

11 REPLIES 11

Lon Landry4
Mega Sage

In the end I was able to solve with Regex. I will keep trying to work out a solution that displays all rows of data instead of just the first. I tried about 10 coding ideas for looping based on Chuck Tomasi's Course, but no luck.

@Lon Landry4 Here is the loop based solution.

function onSubmit() {
//Type appropriate comment here, and begin script below
var assetsIcertify = '[{"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"}]';//g_form.getValue('u_returning_asset_submitted_for');
var assetsIcert = JSON.parse(assetsIcertify);
var submitted_forArray = [];
for(var i=0;i<assetsIcert.length;i++){
    submitted_forArray.push(assetsIcert[i].assets_assigned_to_submitted_for+'');
}

g_form.setValue('certification_results',submitted_forArray.toString());
return;
}

Hope this helps.