REST OUTBOUND MESSAGE JSON FORMAT - ESCAPE CHARACTER BACKSLASH

levino
Giga Guru

Hi There

REST OUTBOUND MESSAGE JSON FORMAT to mid server to runbook

 

i am trying to pass a 

value parameter FolderPath = G:\ak\shared18

it works if the user type in

G:\\ak\\shared18

i still want the user to  type in G:\ak\shared18, is there a way around this

 

do i modify the outbound message to pass thru a escape character

 

Thanks

Levino

1 ACCEPTED SOLUTION

levino
Giga Guru

all sorted , i have used a onload script

View solution in original post

30 REPLIES 30

levino
Giga Guru

on the catalog item when the user type in the path, i need the users to type it

as G:\ak\Shared01

but pass thru G:\\ak\\Shared01

 

 

How are you retrieving the JSON? If you do JSON.stringify(<object>) it will insert the necessary escapes to preserve the string. You can then use JSON.parse(<object>) to access the object properties.

If I understood correctly, you want the user to type only single back slash, but you wanted to pass double black slashes from script?. If this is the requirement then you need to use string manipulation methods.

var str = 'value_entered_by_user';  

var res = str.replace(/\//gi, "\\\\");

levino
Giga Guru

hi there

is this correct,  you had gi in your code, what does it refer to?

 

function onSubmit() {
//Type appropriate comment here, and begin script below
var str = g_form.getValue('new_folder_path');

var res = str.replace(/\//gi, "\\\\");
g_form.setValue('new_folder_path',res);
}

gi is part of the regex. After the actual regular expression (/\//) you can add flags, g makes the regex global so it doesn't return after the first match but continues to parse the string and the i makes it case insensitive.

You can check out common regex's and test your own at various sites such as:

https://regex101.com/