- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 10:51 AM
Hi There,
I have received a request to improve the accuracy of onboarding tickets by implementing validation parameters for name fields and job titles, thereby reducing typos and inaccuracies.
Our Onboarding tickets are frequently entered with incorrect information, such as misspelled names or inaccurate job descriptions. This can lead to issues in processing and tracking.
I have added new fields/variables called: confirmed First Name, Confirm Last Name and Confirm Job Title to the Onboarding form. I have then created a client script to implement the validation part using the script below. Unfortunately, the name fields are still not validating when filling out the form.
Thank you!
Script Used:
function onSubmit() {
// Retrieve field values
var lastName = g_form.getValue('last_name');
var confirmLastName = g_form.getValue('confirm_last_name');
var firstName = g_form.getValue('first_name');
var confirmFirstName = g_form.getValue('confirm_first_name');
var jobTitle = g_form.getValue('job_title');
var confirmJobTitle = g_form.getValue('confirm_job_title');
// Debugging - Log values to the console (use browser developer tools to view)
console.log('Last Name:', lastName);
console.log('Confirm Last Name:', confirmLastName);
console.log('First Name:', firstName);
console.log('Confirm First Name:', confirmFirstName);
console.log('Job Title:', jobTitle);
console.log('Confirm Job Title:', confirmJobTitle);
// Validation logic
if (lastName !== confirmLastName) {
g_form.addErrorMessage('Last names do not match.');
return false; // Prevent form submission
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 11:03 AM
Hi @Swebb ,
to implementing the form validation for your Onboarding tickets in ServiceNow, aimed at ensuring that the name and job title fields match their confirmation counterparts:
How to Implement Form Validation in ServiceNow
Objective: Ensure that when users fill out the Onboarding form, the names and job titles they enter must match the confirmed values before the form can be submitted. This helps reduce errors and inconsistencies.
Steps to Implement Validation
- Create or Edit Client Script
- Navigate to Client Scripts: Go to System Definition > Client Scripts in your ServiceNow instance.
- Create New Client Script: Click on "New" to create a new client script, or edit an existing one if you already have a script set up for this form.
- Configure Basic Details:
- Name: Enter a descriptive name, such as "Onboarding Form Validation".
- Table: Select the table associated with your Onboarding form.
- UI Type: Choose "All" to apply to all UI types or "Desktop" if it’s used only on desktop forms.
- Set Script Type:
- Type: Select onSubmit. This ensures that your script runs when the user tries to submit the form.
- Add Validation Script: Copy and paste the following script into the Script field:
function onSubmit() {
// Retrieve field values from the form
var lastName = g_form.getValue('last_name');
var confirmLastName = g_form.getValue('confirm_last_name');
var firstName = g_form.getValue('first_name');
var confirmFirstName = g_form.getValue('confirm_first_name');
var jobTitle = g_form.getValue('job_title');
var confirmJobTitle = g_form.getValue('confirm_job_title');
// Debugging - Log values to the console (use browser developer tools to view)
console.log('Last Name:', lastName);
console.log('Confirm Last Name:', confirmLastName);
console.log('First Name:', firstName);
console.log('Confirm First Name:', confirmFirstName);
console.log('Job Title:', jobTitle);
console.log('Confirm Job Title:', confirmJobTitle);
// Validation logic
if (lastName !== confirmLastName) {
g_form.addErrorMessage('Last names do not match.');
return false; // Prevent form submission
}
if (firstName !== confirmFirstName) {
g_form.addErrorMessage('First names do not match.');
return false; // Prevent form submission
}
if (jobTitle !== confirmJobTitle) {
g_form.addErrorMessage('Job titles do not match.');
return false; // Prevent form submission
}
// If all validations pass, allow the form to be submitted
return true;
}
Please Mark it as Helpful , If the Solution is Accepted.
Thanks Regards ,
Badrinarayan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 11:03 AM
Hi @Swebb ,
to implementing the form validation for your Onboarding tickets in ServiceNow, aimed at ensuring that the name and job title fields match their confirmation counterparts:
How to Implement Form Validation in ServiceNow
Objective: Ensure that when users fill out the Onboarding form, the names and job titles they enter must match the confirmed values before the form can be submitted. This helps reduce errors and inconsistencies.
Steps to Implement Validation
- Create or Edit Client Script
- Navigate to Client Scripts: Go to System Definition > Client Scripts in your ServiceNow instance.
- Create New Client Script: Click on "New" to create a new client script, or edit an existing one if you already have a script set up for this form.
- Configure Basic Details:
- Name: Enter a descriptive name, such as "Onboarding Form Validation".
- Table: Select the table associated with your Onboarding form.
- UI Type: Choose "All" to apply to all UI types or "Desktop" if it’s used only on desktop forms.
- Set Script Type:
- Type: Select onSubmit. This ensures that your script runs when the user tries to submit the form.
- Add Validation Script: Copy and paste the following script into the Script field:
function onSubmit() {
// Retrieve field values from the form
var lastName = g_form.getValue('last_name');
var confirmLastName = g_form.getValue('confirm_last_name');
var firstName = g_form.getValue('first_name');
var confirmFirstName = g_form.getValue('confirm_first_name');
var jobTitle = g_form.getValue('job_title');
var confirmJobTitle = g_form.getValue('confirm_job_title');
// Debugging - Log values to the console (use browser developer tools to view)
console.log('Last Name:', lastName);
console.log('Confirm Last Name:', confirmLastName);
console.log('First Name:', firstName);
console.log('Confirm First Name:', confirmFirstName);
console.log('Job Title:', jobTitle);
console.log('Confirm Job Title:', confirmJobTitle);
// Validation logic
if (lastName !== confirmLastName) {
g_form.addErrorMessage('Last names do not match.');
return false; // Prevent form submission
}
if (firstName !== confirmFirstName) {
g_form.addErrorMessage('First names do not match.');
return false; // Prevent form submission
}
if (jobTitle !== confirmJobTitle) {
g_form.addErrorMessage('Job titles do not match.');
return false; // Prevent form submission
}
// If all validations pass, allow the form to be submitted
return true;
}
Please Mark it as Helpful , If the Solution is Accepted.
Thanks Regards ,
Badrinarayan