Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Passing script include variable value to REST Message Http Query Parameter Content

swisstech08
Mega Contributor

Hi,

I have a Client Script variable:

    contentUrl = "mySite";

I pass this variable to the Script include and then pass the variable to the REST message

    siteTokenRequest.setRequestHeader('siteContentUrl',contentUrl);

I also tried:

    siteTokenRequest.setQueryParameter('siteContentUrl',contentUrl);

find_real_file.png

When I usde the actual "siteContentUrl" value the request is successful. However, when I use variable substitution ${siteContenUrl} the REST request fails.

Any thoughts?

Sincerely,

Roland

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

try using 

 siteTokenRequest.setStringParameterNoEscape('siteContentUrl', contentUrl);

View solution in original post

4 REPLIES 4

Mike Patel
Tera Sage

try using 

 siteTokenRequest.setStringParameterNoEscape('siteContentUrl', contentUrl);

swisstech08
Mega Contributor

Thank you Mike,

This didn't work. Also I was under the assumption that setStringParfameterNoEscape was used to set parameters for the endpoint and using setQueryParameter was used to set parameters for the http query, but I haven't found a sample or explanation how to set a variable in the content of a post.

Sincerely,

Roland

swisstech08
Mega Contributor

Hi, Is there another way, another method, to pass this variable from the include script to the REST message? I tried different formats/methods and none seem to work.

 

Sincerely,

Roland

On your content tab you need something like. Value of JSON also needs quotes and use 

siteTokenRequest.setStringParameterNoEscape('siteContentUrl', contentUrl);
{
	"credentials":{
		"name":"<user-name>",
		"password":"<password>",
		"site":{
			"contentUrl":"${siteContentUrl}"
		}
	}
}