- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 08:02 AM
Hi i have string variable in a catalog item and I'm setting the value by using below code
g_form.setValue('home_directory' , '\\XXXXX.XXX.XXXX.XXX\share\homedrive');
but it is populating like a \XXXXX.XXX.XXXX.XXXsharehomedrive. without forward slash and backward slash.
How to fix this?
Thanks in Advance
Sravani
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 08:06 AM - edited 10-20-2022 08:25 AM
You'll need to add another \
g_form.setValue('home_directory' , "\\\\XXXXX.XXX.XXXX.XXX\\share\\homedrive");
see this
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0721958
Description
Certain characters, if used in a JavaScript string, can generate unexpected and sometimes hard to identify errors in a script. These Javascript strings can be used within various object types that support scripting in the ServiceNow platform, such as Business Rules, Workflow Scripts, ACL records and many other places in the application. These special characters generally cause an issue because that character has a special significance to the JavaScript language when included in a command.
To allow these characters to thus be used in a String when necessary in the Javascript supported objects in ServiceNow, the character must be escaped (preceded by special characters telling the JavaScript compiler to handle the next character literally rather than attempt to interpret the character in the usual manner).
Method
The three main characters that users will probably need to use and which will require the escape character are the single quote character ('), the double quote character (") and the backslash character (\).
The reason these characters need special handling is because the single and double quote characters are used to begin and terminate a string in JavaScript and the backslash character is the escape character itself.
Escaping these characters is easy, simply place a preceding backlash character (\) in front of the character within the string which you want to have treated literally. Thus, \' would allow usage of a single quote character, \" would allow usage of the double quote character and \\ would allow literal use of a backslash character in a string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 08:06 AM - edited 10-20-2022 08:25 AM
You'll need to add another \
g_form.setValue('home_directory' , "\\\\XXXXX.XXX.XXXX.XXX\\share\\homedrive");
see this
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0721958
Description
Certain characters, if used in a JavaScript string, can generate unexpected and sometimes hard to identify errors in a script. These Javascript strings can be used within various object types that support scripting in the ServiceNow platform, such as Business Rules, Workflow Scripts, ACL records and many other places in the application. These special characters generally cause an issue because that character has a special significance to the JavaScript language when included in a command.
To allow these characters to thus be used in a String when necessary in the Javascript supported objects in ServiceNow, the character must be escaped (preceded by special characters telling the JavaScript compiler to handle the next character literally rather than attempt to interpret the character in the usual manner).
Method
The three main characters that users will probably need to use and which will require the escape character are the single quote character ('), the double quote character (") and the backslash character (\).
The reason these characters need special handling is because the single and double quote characters are used to begin and terminate a string in JavaScript and the backslash character is the escape character itself.
Escaping these characters is easy, simply place a preceding backlash character (\) in front of the character within the string which you want to have treated literally. Thus, \' would allow usage of a single quote character, \" would allow usage of the double quote character and \\ would allow literal use of a backslash character in a string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 08:22 AM
Hi @Vamshi_ch123 ,
Use below code:-
g_form.setValue('home_directory' , "\\\\XXXXX.XXX.XXXX.XXX\\share\\homedrive");
Note: use 4 slash (\\\\);
if it helps you, please mark it correct answer.
Thanks,
Pratik Malviya