- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 11:56 PM
Hi team,
I have written the following three scripts to restrict form submission based on different fields, but I want to combine them into a single script instead of using individual ones. Please help me understand how I can achieve this."
----------------------------
function onSubmit() {
var assignmentGrp = g_form.getValue('servicenow_assignment_group');
if (assignmentGrp == '' || assignmentGrp == undefined) {
g_form.showFieldMsg('servicenow_assignment_group', 'IT Functional Org must be updated within APM# before a CIR submission.', 'error');
return false; // Prevent submission
}
return true;
}
-------------------------------------------------------
function onSubmit() {
var appBunit = g_form.getValue('app_business_unit');
if (appBunit == '' || appBunit == undefined) {
g_form.showFieldMsg('app_business_unit', 'Business unit must be updated within APM# before a CIR submission.', 'error');
return false; // Prevent submission
}
return true;
}
-------------------------------------------------------------
function onSubmit() {
var drTier = g_form.getValue('dr_tier');
if (drTier == '' || drTier == undefined) {
g_form.showFieldMsg('dr_tier', 'Dr tier must be updated within APM# before a CIR submission.', 'error');
return false; // Prevent submission
}
return true;
}
Please help me how can i achieve this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:18 AM
try this
function onSubmit() {
// Check Assignment Group
var assignmentGrp = g_form.getValue('servicenow_assignment_group');
if (!assignmentGrp) {
g_form.showFieldMsg('servicenow_assignment_group', 'IT Functional Org must be updated within APM# before a CIR submission.', 'error');
return false;
}
// Check App Business Unit
var appBunit = g_form.getValue('app_business_unit');
if (!appBunit) {
g_form.showFieldMsg('app_business_unit', 'Business unit must be updated within APM# before a CIR submission.', 'error');
return false;
}
// Check DR Tier
var drTier = g_form.getValue('dr_tier');
if (!drTier) {
g_form.showFieldMsg('dr_tier', 'Dr tier must be updated within APM# before a CIR submission.', 'error');
return false;
}
// All validations passed
return true;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 12:18 AM
try this
function onSubmit() {
// Check Assignment Group
var assignmentGrp = g_form.getValue('servicenow_assignment_group');
if (!assignmentGrp) {
g_form.showFieldMsg('servicenow_assignment_group', 'IT Functional Org must be updated within APM# before a CIR submission.', 'error');
return false;
}
// Check App Business Unit
var appBunit = g_form.getValue('app_business_unit');
if (!appBunit) {
g_form.showFieldMsg('app_business_unit', 'Business unit must be updated within APM# before a CIR submission.', 'error');
return false;
}
// Check DR Tier
var drTier = g_form.getValue('dr_tier');
if (!drTier) {
g_form.showFieldMsg('dr_tier', 'Dr tier must be updated within APM# before a CIR submission.', 'error');
return false;
}
// All validations passed
return true;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 02:04 AM
@JVINAY ,try this.
function onSubmit() {
var fields = ["servicenow_assignment_group","app_business_unit", "dr_tier"];
var msgMap = {
"servicenow_assignment_group": "IT Functional Org must be updated within APM# before a CIR submission.",
"app_business_unit": "Business unit must be updated within APM# before a CIR submission.",
"dr_tier":"Dr tier must be updated within APM# before a CIR submission."
};
fields.forEach(function(f){
var field = g_form.getValue(f);
if (field == '' || field == undefined) {
g_form.showFieldMsg(f, msgMap[f], 'error');
return false; // Prevent submission
}
return true;
});
}
Mark correct if you find this helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 02:18 AM
function onSubmit() {
var valid = true;
var assignmentGrp = g_form.getValue('servicenow_assignment_group');
if (!assignmentGrp) {
g_form.showFieldMsg('servicenow_assignment_group', 'IT Functional Org must be updated within APM# before a CIR submission.', 'error');
valid = false;
}
var appBunit = g_form.getValue('app_business_unit');
if (!appBunit) {
g_form.showFieldMsg('app_business_unit', 'Business unit must be updated within APM# before a CIR submission.', 'error');
valid = false;
}
var drTier = g_form.getValue('dr_tier');
if (!drTier) {
g_form.showFieldMsg('dr_tier', 'Dr tier must be updated within APM# before a CIR submission.', 'error');
valid = false;
}
return valid; // only submit if all fields are valid
}