Regex for Server Folder/Path Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 12:03 AM
Hi,
I am trying to write an onChange logic on 2 fields---- the requirement is
Target (server with share): Single Line Text
Field Validation Checks on:
- must start with \\
- read out the FQDN --> between \\ and the next \
- FQDN exists in ServiceNow in class storage or server
Example: \\fr0-abc.xy.server.com\pc_hello_stp_00
File Path: Single Line Text
Field validation checks on:
- starts with \\res.myserver.corp
Example: \\res.myserver.corp\ACE\Computer_XX0\WW000
Regards,
Piyush Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 01:06 AM
Hi @Piyush27
For your first example, please try the following code in Fix Script, then apply it to your code:
var fieldValue = "\\\\fr0-abc.xy.server.com\\pc_hello_stp_00" ; var regexPattern = /\\\\(.*?)\\/; // Use the regular expression to extract the content var match = fieldValue.match(regexPattern); if (match && match.length >= 2) { // The extracted content is in match[1] var extractedContent = match[1]; gs.info(">>>Extracted Content: " + extractedContent); } else { gs.info(">>>No match found for the regular expression"); }
For the second example, I don't think you will need regular expression, you just need startsWith to check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 01:45 AM
Thanks, @DYCM but it did not work.
The requirement is when a user enters the server path/name in the single-line text box it should do a check
The server path/name should start with \\
then
\\some_name_here_1\some_text_here_2
basically starts with \\ and ends with \