- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I have created a requested item to create/modify a SharePoint site. If the request type field is Permissions Management, at lest one of the Level of Access fields needs to be filled out(see screenshot). If at lest one is not filled out, I need to generate an error message. I'm not quit sure how to do this. Any assistance would be greatly appreciated.
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
53m ago
Hi @vcaracci75 ,
To show just one error message at the top of the form — instead of repeating it under each field — you can use g_form.addErrorMessage() instead of g_form.showFieldMsg().
Updated Script (Single Error Message at Top):
function onSubmit() {
var requestType = g_form.getValue('request_type'); // Adjust to your actual field name
var readOnly = g_form.getValue('read_only_groups_users');
var contribute = g_form.getValue('contribute_groups_users');
var other = g_form.getValue('other_please_note');
if (requestType === 'Permissions Management') {
if (!readOnly && !contribute && !other) {
g_form.addErrorMessage('At least one access level must be specified.');
return false; // Prevent submission
}
}
return true; // Allow submission
}
What This Does:
- g_form.addErrorMessage() places a single error banner at the top of the form.
- It avoids cluttering each field with the same message.
- It’s ideal for validations that apply to a group of fields collectively.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Best,
Anupam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
53m ago
Hi @vcaracci75 ,
To show just one error message at the top of the form — instead of repeating it under each field — you can use g_form.addErrorMessage() instead of g_form.showFieldMsg().
Updated Script (Single Error Message at Top):
function onSubmit() {
var requestType = g_form.getValue('request_type'); // Adjust to your actual field name
var readOnly = g_form.getValue('read_only_groups_users');
var contribute = g_form.getValue('contribute_groups_users');
var other = g_form.getValue('other_please_note');
if (requestType === 'Permissions Management') {
if (!readOnly && !contribute && !other) {
g_form.addErrorMessage('At least one access level must be specified.');
return false; // Prevent submission
}
}
return true; // Allow submission
}
What This Does:
- g_form.addErrorMessage() places a single error banner at the top of the form.
- It avoids cluttering each field with the same message.
- It’s ideal for validations that apply to a group of fields collectively.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Best,
Anupam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
38m ago
Hi @vcaracci75 ,
Use g_form.addErrorMessage() in a Catalog Client Script to display validation errors that prevent form submission in Requested Items
onSubmit Client Script Setup
Catalog Client Script on your Requested Item:
Type: onSubmit
Applies to: Your SharePoint site item
function onSubmit() {
// Example: Check if request_type is Permissions Management
if (g_form.getValue('request_type') == 'permissions_management') {
// Check if at least one Level of Access is selected
var readAccess = g_form.getValue('read_access');
var contributeAccess = g_form.getValue('contribute_access');
var fullControl = g_form.getValue('full_control_access');
var hasAccess = (readAccess == 'true') ||
(contributeAccess == 'true') ||
(fullControl == 'true');
if (!hasAccess) {
g_form.addErrorMessage('At least one Level of Access must be selected for Permissions Management requests.');
return false; // Blocks submission
}
}
return true; // Allows submission
}Error Message Features
Red banner appears at top of form
Prevents submit when return false
Field highlighting (optional with g_form.setMandatory() or g_form.showFieldMsg())
Clears automatically on field change or page refresh
Field-Level Error
For specific field focus/highlighting:
g_form.showFieldMsg('read_access', 'Select at least one access level', 'error');
g_form.showFieldMsg('contribute_access', 'Select at least one access level', 'error');This creates inline red error messages under specific variables
Please refer to the below link:-
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0727685
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0694100
