- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 03:37 AM
Hi Team
I have a mrvs , with the below client script which works fine.
e.g it sets the below to the mrvs_description variable.
Item #1:
Dealer_Code : df
Dealer_Name : dfdf
Effective_Date : 09/08/2024
Dealer_Address : ddf
Dealer_Type : Consumer
Hub_Dealer_Code : false
SRS_Dealer_Code : true
Store_Manager : dff
I have another requirement where if Dealer Type == Consumer then setvalue on another variable.
if(dealer_type == 'Consumer'){g_form.setvalue('request_template','test')
}
not sure if the above will work, please help with a onsubmit client script
note dealer type is a select box variable type
function onSubmit() {
var output = "";
var variables_names = ['Dealer_Code','Dealer_Name','Effective_Date','Dealer_Address','Dealer_Type','Hub_Dealer_Code','SRS_Dealer_Code','Store_Manager'];
//get values from the Multirow variables
var vset_value = g_form.getValue("IO:2db810c7db6d90d0304c147a3a9619c1");
var json_obj = JSON.parse(vset_value);
for(var i = 0; i < json_obj.length; i++){
output+= "\n"+ 'Item #' + (i+1) + ":\n";
var row = json_obj[i];
for(var j = 0; j < variables_names.length; j++){
if(row[variables_names[j]] != ""){
output+= variables_names[j] + ' : ' + row[variables_names[j]] + "\n";
}
}
}
g_form.setValue('mrvs_description', output);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 04:59 AM
Hi @levino
print the log from if condition and check condition matching or not also use actual field name instead of 'request_template'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 04:04 AM
Hi @levino ,
Can you try the below script , I have parsed the JSON and set the value accordingly:
var mrvs_value = g_form.getValue('<name of the MRVS>');
var jsonobj = JSON.parse(mrvs_value);
var length = jsonobj.length;
for (var i = 0; i < length; i++) {
if (jsonobj[i].<MRVS Variable name> == '<Value>') {
g_form.setValue(jsonobj[i].<MRVS Variable name>,'<Value to be set>');
}
}
Please mark helpful/correct if my response helped you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 06:06 PM
Hi Anubhav
mrvs variable name in my case would be 'dealer_type' and value would be 'consumer'
f (jsonobj[i].<MRVS Variable name> == '<Value>') {
g_form.setValue(jsonobj[i].<MRVS Variable name>,'<Value to be set>');
}
}
g_form.setValue mrvs variable name here your referring to 'request_template', value can be anything 'test'
Thanks
Levino
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 04:13 AM
hi @levino
To accomplish what you're aiming to do—setting a value based on a select box (dealer_type) and handling multi-row variables in an onsubmit client script—you need to ensure that your script correctly handles both scenarios. Below are improvements and corrections for your script.
function onSubmit() {
// Get the value of the dealer_type field
var dealerType = g_form.getValue('dealer_type'); // Use the actual field name here
// Set the request_template field based on the dealer_type value
if (dealerType == 'Consumer') {
g_form.setValue('request_template', 'test'); // Use the actual field name here
}
// Initialize output variable for multi-row variables
var output = "";
var variables_names = ['Dealer_Code','Dealer_Name','Effective_Date','Dealer_Address','Dealer_Type','Hub_Dealer_Code','SRS_Dealer_Code','Store_Manager'];
// Get values from the Multi-row variable
var vset_value = g_form.getValue("IO:2db810c7db6d90d0304c147a3a9619c1"); // Use the actual variable name here
if (vset_value) {
var json_obj = JSON.parse(vset_value);
for (var i = 0; i < json_obj.length; i++) {
output += "\n" + 'Item #' + (i + 1) + ":\n";
var row = json_obj[i];
for (var j = 0; j < variables_names.length; j++) {
if (row[variables_names[j]]) {
output += variables_names[j] + ' : ' + row[variables_names[j]] + "\n";
}
}
}
}
// Set the output to the 'mrvs_description' field
g_form.setValue('mrvs_description', output);
// Return true to allow form submission
return true;
}
I hope my answer helps you to resolve your issue, if yes please mark my answer as correct & helpful.
THANK YOU
rajesh chopade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 04:34 AM
Did you try this AI generated answer yourself?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark