Catalog item - calling REST method json name value pair

levino
Giga Guru

Hi there

i have a catalog item which calls a REST api, in the http method i have JSON name value pair

 

one of the values  i need to pass is in this format

\\telcom\data\al\shared11\Tyco

 

when i try and test it using the http method it comes up with object of intance not to be found, if i remove that name value pair it goes thru fine

 

do i need to do something to retain the backslash, is it a onclient submit script since it will be eventually passed from a cat item

Thanks

Levino

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@levino 

you can escape the character

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

thanks Ankur

sorry first time using a escape expresion in my run script activity, just whenever free would u know were would it fit in the below, folder path is the variable that contain the backslashes

 

workflow.scratchpad.Path = current.variables.folderPath;

var gr = new GlideRecord('sys_rest_message');
gr.addQuery('name', 'MiB SC-Orch Job Management');
gr.query();

if (gr.next()){
	var restMessage = gr.getUniqueValue();
	var grHttpMethod = new GlideRecord('sys_rest_message_fn');
	grHttpMethod.addQuery('rest_message', restMessage);
	grHttpMethod.addQuery('function_name',current.cat_item.name);
	grHttpMethod.query();
	
	if (grHttpMethod.next()){
		workflow.scratchpad.message = grHttpMethod.sys_id;
	}

 

SwarnadeepNandy
Mega Sage

Hello @levino,

 

This is most likely because backslashes are special characters in JSON that need to be escaped with another backslash. For example, if you want to pass the value \telcom\data\al\shared11\Tyco, you need to write it as \\telcom\data\al\shared11\Tyco in your JSON string 

You can also use the JSON_UNESCAPED_SLASHES option in the json_encode() function to prevent backslas.... However, this option is only available in PHP and not in servicenow. Alternatively, you can use a script to replace the backslashes with another character before sending....

 

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy