- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-27-2020 04:00 PM
Hi,
I have an Onsubmit client script that should check if for each rows, 1 variable: 'member_replacement' is not empty and all rows are filled in. How to achieve this?
We are auto-populating the addtion of row and users need to update each row variable:member_replacement
below is my current script but not working . Thank you.
function onSubmit() {
//Type appropriate comment here, and begin script below
var multiRowVariableSet = JSON.parse(g_form.getValue('group_creation_members')); //internal name mrvs
var numberOfRows = multiRowVariableSet.length;
for (var i = 0; i < multiRowVariableSet.length; i++) {
alert(numberOfRows);
if(multiRowVariableSet[i].member_replacement == ""){ //variable name
alert("With Value "+ multiRowVariableSet.member_replacement + " " + multiRowVariableSet.group_member_name);
}
else{
alert("Without Value "+ multiRowVariableSet.member_replacement + " " + multiRowVariableSet.group_member_name);
}
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-27-2020 08:59 PM
So you want to check if both the variables are non-empty
if any row has both the variables as empty then stop form submission
update as below
function onSubmit() {
//Type appropriate comment here, and begin script below
var mrv = JSON.parse(g_form.getValue('group_creation_members')); // mrvs internal name
if (mrv.length >= 1){
alert(mrv);
var memberArrCount = 0;
var replacingArrCount = 0;
for (var i=0; i<mrv.length; i++){
if(mrv[i].member_replacement != '')
memberArrCount++;
if(mrv[i].group_member_who_are_you_replacing != '')
replacingArrCount++;
}
if(mrv.length != memberArrCount && mrv.length != replacingArrCount){
alert('empty column');
return false;
}
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-27-2020 08:24 PM
Hello
Refer for help,
If answer is helpful please mark correct and helpful!
Thanks,
Pratiksha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-27-2020 08:59 PM
So you want to check if both the variables are non-empty
if any row has both the variables as empty then stop form submission
update as below
function onSubmit() {
//Type appropriate comment here, and begin script below
var mrv = JSON.parse(g_form.getValue('group_creation_members')); // mrvs internal name
if (mrv.length >= 1){
alert(mrv);
var memberArrCount = 0;
var replacingArrCount = 0;
for (var i=0; i<mrv.length; i++){
if(mrv[i].member_replacement != '')
memberArrCount++;
if(mrv[i].group_member_who_are_you_replacing != '')
replacingArrCount++;
}
if(mrv.length != memberArrCount && mrv.length != replacingArrCount){
alert('empty column');
return false;
}
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-27-2020 09:11 PM
Hi Ankur, thank u for your reply, apologies, i updated the question just now as i just received a change in requirement, i just need 1 variable checking 'member_replacement' need to iterate in each row to check if this is already populated, below is the script i created but not evaluating correctly can u check below?
function onSubmit() {
//Type appropriate comment here, and begin script below
var multiRowVariableSet = JSON.parse(g_form.getValue('group_creation_members')); //internal name mrvs
var numberOfRows = multiRowVariableSet.length;
for (var i = 0; i < multiRowVariableSet.length; i++) {
alert(numberOfRows);
if(multiRowVariableSet[i].member_replacement == ""){ //variable name
alert("With Value "+ multiRowVariableSet.member_replacement + " " + multiRowVariableSet.group_member_name);
}
else{
alert("Without Value "+ multiRowVariableSet.member_replacement + " " + multiRowVariableSet.group_member_name);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-27-2020 10:02 PM
Hi Ankur,
I am able to modify your code to below and it works š thanks for the help!
function onSubmit() {
//Type appropriate comment here, and begin script below
var mrv = JSON.parse(g_form.getValue('group_creation_members')); // mrvs internal name
if (mrv.length >= 1){
//alert(mrv.length);
var memberArrCount = 0;
for (var i=0; i<mrv.length; i++){
if((mrv[i].member_replacement == 'yes') ||(mrv[i].member_replacement == 'no')) //yes-no field
memberArrCount++;
//alert(mrv + " " +memberArrCount );
}
if (mrv.length != memberArrCount){
return false;
}
else{
return true;
}
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-27-2020 10:31 PM
Glad to know.
Please mark my response as correct and helpful to close the question and also benefit future readers.
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader