How to hard code a url and then enter the suffix to that url, only hypen & under scores are allowed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 12:31 PM
Just wanted to share this here so if anyone working on similar requirement can leverage it.
I got a catalog requirement to create a variable on the catalog form to enter URL and it should always start with a url then followed by a suffix to that url, this prefix url is always fixed, it wont change as shown below ( see image below)
https://theabc.sharepoint.com/sites/YourURL
in above url " https://theabc.sharepoint.com/sites/ " is always fixed, user should only enter the url they wanted by appending it to this fixed url like https://theabc.sharepoint.com/sites/create share point sit.....
and this YourURL part should allow user to enter alpha numeric and Under scores and hypens and not any other special characters are allowed.
.
To achieve this i used an onchange client script + regex code
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != '') {
//var regex = /^https:\/\/theabc.sharepoint.com\/sites\/.*$/;
var regex = /^https:\/\/thehartford.sharepoint.com\/sites\/(?:[A-Za-z0-9_-]+)*$/;
if (!regex.test(newValue)) {
g_form.clearValue('provide_the_custom_url');
g_form.showFieldMsg('provide_the_custom_url', "Please follow the url format in the help text, enter the url you wanted into 'YourURL' space,only Hypens and under scores are allowed.", "error");
}
}
}
Line 4 in below code can be used if customer wants to allow any characters
Output :
Test1 :
in above case didn't enter in correct format https://theabc.sharepoint.com/sites/YourURL so it thrown error msg to check help text and follow it.
Test2 :
in this case entered correct format, and in Your URL space entered the url i wanted using hypens and under scroes, no error displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 07:33 PM
try this
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != '') {
var regex = /^https:\/\/theabc\.sharepoint\.com\/sites\/[A-Za-z0-9_-]+$/;
if (!regex.test(newValue)) {
g_form.clearValue('provide_the_custom_url');
g_form.showFieldMsg('provide_the_custom_url', "Please follow the URL format in the help text. Enter the URL you want into the 'YourURL' space. Only hyphens and underscores are allowed.", "error");
}
}
}
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
02-11-2025 08:04 PM
it worked fine for me and allowed underscore and hyphen, It didn't allow @ or any other special character
function onChange(control, oldValue, newValue, isLoading) {
g_form.hideFieldMsg('provide_the_custom_url');
if (newValue != '') {
var regex = /^https:\/\/theabc\.sharepoint\.com\/sites\/[A-Za-z0-9_-]+$/;
if (!regex.test(newValue)) {
g_form.clearValue('provide_the_custom_url');
g_form.showFieldMsg('provide_the_custom_url', "Please follow the URL format in the help text. Enter the URL you want into the 'YourURL' space. Only hyphens and underscores are allowed.", "error");
}
}
}
Output:
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