In servicenow, give assignment on new catalog item to create and put validations on variables, make a assignment to implement it in instance
Assistant
User
Just like part 2 , make more scenerios that implement with the help of catalog client script and ui policies
Assistant
Assignment: Create a New Catalog Item in ServiceNow with Validation on Variables
Objective:
Your task is to create a new Service Catalog item in your ServiceNow instance that requires users to input several variables. Implement validations on these variables to ensure that the data entered is valid and meets specific criteria.
Part 1: Create the Catalog Item
Navigate to Service Catalog:
Go to Self-Service > Service Catalog > Catalog Definitions > Maintain Items.
Create a New Catalog Item:
Click on New to create a new catalog item.
Fill in the following fields:
Name: Enter a descriptive name for your catalog item. (e.g., "Request Access to Software")
Short Description: A brief description of what the catalog item does.
Description: A detailed description of the service being offered.
Catalogs: Select the catalogs where this item should be visible.
Category: Assign a category for easier navigation.
Add Variables:
Switch to the Variables tab and add the following variables with the specified types:
Variable Name: Software Name
Type: Single Line Text
Question: What software do you need access to?
Variable Name: Justification
Type: Multi-Line Text
Question: Please provide a justification for this request.
Variable Name: Access Level
Type: Select Box
Question: Select your required access level.
Choices: Options such as "View Only," "Edit," "Admin."
Variable Name: Email
Type: Email
Question: Enter your email address.
Part 2: Implement Validations on Variables
Go to the Catalog Item:
Open the catalog item you just created.
Add Client Script for Validations:
Click on the Related Links section and select New under the Catalog Client Scripts.
Create a new Client Script to validate the input:
Name: Validate Software Request
Type: onSubmit
Script:
javascript
function onSubmit() {
var softwareName = g_form.getValue('software_name');
var justification = g_form.getValue('justification');
var accessLevel = g_form.getValue('access_level');
var email = g_form.getValue('email');
// Validate Software Name
if (softwareName.trim() === "") {
g_form.addErrorMessage("Please enter the software name.");
return false; // Cancel submission
}
// Validate Justification
if (justification.trim() === "") {
g_form.addErrorMessage("Justification is required.");
return false; // Cancel submission
}
// Validate Access Level
if (accessLevel === "") {
g_form.addErrorMessage("Please select an access level.");
return false; // Cancel submission
}
// Validate Email Format (basic regex)
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
g_form.addErrorMessage("Please enter a valid email address.");
return false; // Cancel submission
}
return true; // Allow submission
}
Test the Catalog Item:
Navigate back to the Service Catalog and search for your new catalog item.
Part 3: Documentation and Submission
Document Your Work:
Write a brief summary of your catalog item, its purpose, and the validations you implemented.
Include screenshots where necessary to illustrate the catalog item and error messages.
Submit Your Assignment:
Provide the documented summary, including screenshots and the Client Script.
Ensure your ServiceNow instance is in a stable state before submitting.
Note: This assignment will help you practice the ServiceNow Service Catalog and Client Script functionalities, essential components for custom application development and management within the ServiceNow platform.
Certainly! Below are additional scenarios that implement various validations and functionalities using Catalog Client Scripts and UI Policies in ServiceNow. Each scenario includes a description and the necessary script or policy to implement the desired behavior.
Scenario 1: Conditional Variable Display
Description:
Show or hide a variable based on the selection of another variable. If a user selects "Other" from a drop-down list, a text input should appear for them to specify their selection.
Variables:
Variable Name: Software Type
Type: Select Box
Question: Select the type of software
Choices: Options include "Commercial," "Open Source," "Other"
Variable Name: Specify Other Software Type
Type: Single Line Text
Question: Please specify
Visible by Default: No (hidden by default)
UI Policy to Control Visibility:
Go to Maintain Items, open your catalog item, and navigate to the UI Policies related list.
Click New.
Short description: Show Specify Other Software Type
Table: Requested Item
Conditions:software_type == "Other"
Actions:
Set Visible: Specify Other Software Type (True)
Scenario 2: Dynamic Default Value Setting
Description:
Set a default value for a variable based on the user’s role or department. If a user from the "IT" department submits a request, default a variable accordingly.
Variable:
Variable Name: Default Project
Type: Single Line Text
Question: Enter the project name
Catalog Client Script for Default Value:
Click on Related Links and select New under Catalog Client Scripts.
Fill in the fields as follows:
Name: Set Default Project Name
Type: onLoad
Script:
javascript
function onLoad() {
var userDept = g_user.department; // get user's department
if (userDept === 'IT') {
g_form.setValue('default_project', 'IT_Project_2023'); // Set default value for IT dept
} else if (userDept === 'HR') {
g_form.setValue('default_project', 'HR_Project_2023'); // Set default value for HR dept
}
// Add more department conditions as necessary
}
Scenario 3: Validation on Variable Input Length
Description:
Ensure that the input for a specific variable meets a minimum character length requirement.
Variable:
Variable Name: Issue Description
Type: Multi-Line Text
Question: Describe the issue you are facing
Catalog Client Script for Validation:
Click on New under Catalog Client Scripts.
Fill in the details:
Name: Validate Issue Description Length
Type: onSubmit
Script:
javascript
function onSubmit() {
var issueDescription = g_form.getValue('issue_description');
if (issueDescription.length < 20) {
g_form.addErrorMessage("Issue description must be at least 20 characters long.");
return false; // Cancel submission
}
return true; // Allow submission
}
Scenario 4: Restrict Variable Input Based on User Selection
Description:
Disable the input of one variable if another variable is set to a specific value. For example, if the user selects "No" for a "Do you require additional notes?" variable, the "Additional Notes" variable should be disabled.
Variables:
Variable Name: Require Additional Notes
Type: Select Box
Question: Do you require additional notes?
Choices: "Yes," "No"
Variable Name: Additional Notes
Type: Multi-Line Text
Question: Please provide additional notes
Visible by Default: Yes
UI Policy to Disable Input:
Go to Maintain Items, select your catalog item, and navigate to UI Policies.
Click New to create a UI Policy:
Short Description: Disable Additional Notes
Conditions:require_additional_notes == "No"
Actions:
Set Mandatory: Additional Notes (False)
Set Read Only: Additional Notes (True)
Scenario 5: Confirmations for Critical Requests
Description:
Prompt users to confirm their request when they select a specific option from a dropdown variable, such as deleting an account.
Variable:
Variable Name: Action to Perform
Type: Select Box
Question: Select action
Choices: "Create Account," "Delete Account"
Catalog Client Script for Confirmation:
Click on New under Catalog Client Scripts.
Fill in the details:
Name: Confirm Critical Action
Type: onSubmit
Script:
javascript
function onSubmit() {
var action = g_form.getValue('action_to_perform');
if (action === "Delete Account") {
var answer = confirm("Are you sure you want to delete this account? This action cannot be undone.");
if (!answer) {
return false; // User canceled the action
}
}
return true; // Allow submission
}
These scenarios provide different use cases for implementing validation and conditional behavior in ServiceNow Service Catalog items using Catalog Client Scripts and UI Policies. You can modify the variable names and conditions to tailor them to your specific requirements.