Does not contain query in onsubmit script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 05:59 AM
Hi All,
Basically, my requirement is a prefix check on the form , if the name does not contain the "GDC" prefix, the form should not be saved, preventing the user from changing the prefix.
Based on the organization, name prefix will automatically populate, attached screenshot for reference.
Tried this code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 07:08 AM
Hi @chitra1
You can use this onSubmit Client Script
function onSubmit() {
var name = g_form.getValue('name'); //change variable name accordingly
var prefix = 'IN-GDC';
if (name.indexOf(prefix) !== 0) {
g_form.addErrorMessage('Name must start with the prefix "GDC". Please correct before submitting the form.');
return false; // Prevent form submission
}
return true; // Allow form submission
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 09:45 PM
Hi @Sohithanjan G ,
I have added the same script for other options as well,but its showing the IN-GDC error only.
Thanks,
CD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 10:26 PM
Hi @chitra1 ,
You cannot use multiple logics here in that format. Try below
function onSubmit() {
var name = g_form.getValue('name'); //change variable name accordingly
var prefixes = ['IN-GDC', 'DC', /* Add more prefixes here */];
var validPrefix = false;
for (var i = 0; i < prefixes.length; i++) {
if (name.indexOf(prefixes[i]) === 0) {
validPrefix = true;
break;
}
}
if (!validPrefix) {
var errorMessage = 'Name must start with one of the following prefixes: ';
for (var j = 0; j < prefixes.length; j++) {
errorMessage += '"' + prefixes[j] + '"';
if (j < prefixes.length - 1) {
errorMessage += ', ';
}
}
errorMessage += '. Please correct before submitting the form.';
g_form.addErrorMessage(errorMessage);
return false; // Prevent form submission
}
return true; // Allow form submission
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 11:18 PM - edited 03-11-2024 11:19 PM
Hi Chitra,
You are getting this "IN-GDC" error only because the first line of if code is not satisfying the condition when there is "IN_GDC" present in the name and it skips the if part and goes to else part and when "IN-GDC" is present then it prints the error message from first if block only. In this case you can used nested if approach to get the desired result.