File Path Name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2022 01:19 PM
I have a single text field on a service catalog form in which a user can enter a full file path. There are two restrictions:
- The path must start with "\\". An good example would be \\svrp12345\public\filename
- The value between "\\" and "\" cannot contain "nas" in any position so the following values would not be allowed: \\nas123\public\filename or \\123nas\public\filename
Here is the script I put together with "full_file_path_for_the_requested_folder" being the name of the field that captures the full file name path.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var msg = "The file path should start with \\\\";
var str = newValue;
if (str.startsWith('\\\\')){
return true;
}
else;
{
g_form.setValue('full_file_path_for_the_requested_folder', '');
g_form.showErrorBox('full_file_path_for_the_requested_folder', msg, true);
}
}
This script works well in fulfilling the first restriction however, I can enter "\\\" for the start of my file name without getting an error.
Can anyone please assist in correcting my script or suggesting a regex.
Thank you.
Tony Capone

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2022 01:48 AM
Hi Tony,
Try the following script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue.startsWith('\\\\') && !newValue.startsWith('\\\\\\') && !newValue.includes('nas')) {
g_form.showFieldMsg('full_file_path', 'full file path is OK.', 'info');
} else {
g_form.showFieldMsg('full_file_path', 'full file path is NG.', 'error');
}
}
execution result:
case 1: \\svrp12345\public\filename
case 2: \\\svrp12345\public\filename
case 3: \\nas123\public\filename
case 4:\\123nas\public\filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2022 06:59 AM
You could use use 4 backslashes to bypass this. Additionally 'nas' cannot be used anywhere in the path (not only in the first folder as initially requested).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2022 07:04 AM
This can be solved with regex only, no need for a client script.
Add a new Variable Validation Regex (Service Catalog > Catalog Variables > Variable Validation Regex) using the following configuration:
Name: Network Path (no NAS)
Regular Expression: ^\\\\((?!nas)[^\\])*(\\[^\\])+$
Regex Flag: Case Insensitive
Now update your variable to include the regex:
Please let us know if this solved your problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2022 08:03 AM
Hi Tony,
Changed the script to only look for "nas" in the root directory.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var g = newValue.replace(/^\\\\/,'').replace(/\\.*/, '');
if (newValue.startsWith('\\\\') && !newValue.startsWith('\\\\\\') && !g.includes('nas')) {
g_form.showFieldMsg('full_file_path', 'full file path ' + newValue + ' is OK.', 'info');
} else {
g_form.showFieldMsg('full_file_path', 'full file path ' + newValue + 'is NG.', 'error');
}
}
Execution results:
case 1:\\svrp12345\public\filename
case 2: \\\svrp12345\public\filename
case 3: \\nas123\public\filename
case 4:\\123nas\public\filename