- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 01:58 PM
I am trying to write an onSubmit client script that gets all values of a specific variable. I have seen numerous articles on roughly the same subject but none of the solutions have worked. The data comes from JSON populated via a MRVS. (Seems like MRVS were released "half-baked", most simple use cases require a lot of scripting...)
The String is I am searching:
[{"tb_submitted_for":"4cfb00b0c3d599d07ee3251ce0013178","state_submitted_for":"In use","assets_assigned_to_submitted_for":"f7fad3adc34991907ee3251ce00131d9"},{"tb_submitted_for":"4cfb00b0c3d599d07ee3251ce0013178","state_submitted_for":"In use","assets_assigned_to_submitted_for":"1d4601d6376e83046b75d5c543990e81"}]
I am trying to extract the text in black bold italics above.
The below script only extracts the first value of assets_assigned_to_submitted_for.
The number of the occurrences of assets_assigned_to_submitted_for changes with each request. Maybe one, maybe four or more.
function onSubmit() {
//Type appropriate comment here, and begin script below
var json1 = g_form.getValue("certification_results");
//var json2 = g_form.getValue("results_assign_to_another_user");
var myJSON = '{"tb_submitted_for":"4cfb00b0c3d599d07ee3251ce0013178", "state_submitted_for":"In use", "assets_assigned_to_submitted_for":"1d4601d6376e83046b75d5c543990e81"}';
var myObj = JSON.parse(myJSON);
var innerHTML = myObj["assets_assigned_to_submitted_for"];
var results = JSON.stringify(innerHTML);
g_form.setValue('results_compared',results);
return;
}
}
I have tried using for,let,next and while without success.
What can I use to find values for all occurrences of a variable within a string (assets_assigned_to_submitted_for)?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 11:19 PM - edited 05-09-2023 11:22 PM
Hi Lon,
Please use the below script, you will the value of the field "assets_assigned_to_submitted_for"
BackGround Script to check :
*** Script: [object Object],[object Object]
*** Script: Test value array->f7fad3adc34991907ee3251ce00131d9,1d4601d6376e83046b75d5c543990e81
- Kailas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 11:19 PM - edited 05-09-2023 11:22 PM
Hi Lon,
Please use the below script, you will the value of the field "assets_assigned_to_submitted_for"
BackGround Script to check :
*** Script: [object Object],[object Object]
*** Script: Test value array->f7fad3adc34991907ee3251ce00131d9,1d4601d6376e83046b75d5c543990e81
- Kailas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 05:42 AM
Thanks for your helpful suggestion!
My item now works as expected.
I need to study parse & stringify in detail. I have read a lot on subject (JavaScript The Definitive guide, W3School, community, etc.) but the abstract aspects are hard for me to grasp.
Thanks for your time,
Lon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 08:11 AM
Hi @Lon Landry4
I am glad that your issue is fixed.
- Kailas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 07:41 PM
I am still trying to get a solution for this.
Ex.[{"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"}]
I need to pull the sys_id of each assets_assigned_to_submitted_for above.
The number of rows will vary.
I have spent hours looking at different ideas...