How to restrict user to enter only specific vales in Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 01:44 AM
How to restrict a user to enter only specific values like "(“/”, “/usr”, “/home”, “/boot”, “/boot/efi”, “/dev”, “/tmp”, “/var”, “/opt) in a single line text in a Catalog?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 01:57 AM
Hi @Sowmya
did you try with UI policy
Like
contains
these words.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 02:34 AM
Hello @Sowmya ,
Please try the below code in catalog client script and see how it works for you , I have tested it from my end and its working fine for me so just let me know your views on this.
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var forbiddenValues = ["/", "/usr", "/home", "/boot", "/boot/efi", "/dev", "/tmp", "/var", "/opt"];
for (var i = 0; i < forbiddenValues.length; i++) {
if (newValue.includes(forbiddenValues[i])) {
var errorMessage = "Invalid value. The entered value is not allowed.";
alert(errorMessage);
g_form.setValue('description', ''); // Clear the 'description' field if an invalid value is entered
return;
}
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 02:39 AM
Hi @Sowmya
The simplest way to do this is to make use of the Validation Regex functionality. Define a regular expression for a variable by referring this link https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/product/service-catalog-management... and with regular expression ^(\/[^/ ]*)+\/?$
Then configure the Validation Regex for your Single Line Text as below :
Output :
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 03:00 AM
Hi @Sowmya
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************