Rest Messages and System Properties

Omar_Sanchez
Tera Contributor

Hello, I am working with Rest Messages and scheduled imports to make a rest request. following the servicenow docs 
https://docs.servicenow.com/bundle/newyork-application-development/page/integrate/outbound-rest/task...


I see that the endpoint may include variables using the format ${variable}. I currently have a system property an.example.property that I am using as a parameter for the endpoint field in the format ${an.example.property}. Running tests on this endpoint I am seeing that the endpoint field is not being populated with the system property value. Am I using this correctly?

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hi,

You may need to use:

property(gs.getProperty)

and perhaps assign that to a variable, then use ${variable}.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Isn't it gs.getProperty('an.example.property")?

Hi,

Yep. I was merely meaning to mention the gs.getProperty(); portion and include I link, just didn't come back to the post as I got caught up in something at work.

https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_ScopedGlideSystemGetProperty_String...


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you for the helpful comment Allen. In my scheduled jobs I have the following script that was generated. does the rest message take these system variables as a parameter?

try { 
	 var r = new sn_ws.RESTMessageV2('x_192652_device42.d42_rest_devices_path', 'GET_devices');

	//override authentication profile 
	//authentication type ='basic'/ 'oauth2'
	//r.setAuthenticationProfile(authentication type, profile name);

	//set a MID server name if one wants to run the message on MID
	//r.setMIDServer('MY_MID_SERVER');

	//if the message is configured to communicate through ECC queue, either
	//by setting a MID server or calling executeAsync, one needs to set skip_sensor
	//to true. Otherwise, one may get an intermittent error that the response body is null
	//r.setEccParameter('skip_sensor', true);


	//endpoint for the following rest message ${device42_base_url}/${device42_instance_guid}/${device42_devices_path}
	//get the system property values
	var device42_base_url = gs.getProperty('example.property');
	var device42_instance_guid = gs.getProperty('example.property');
	var device42_devices_path = gs.getProperty('example.property');

	//todo
	//now that we have the system property values, do they need to be passed to the rest message?
	

	var response = r.execute();
	var responseBody = response.getBody();
	var httpStatus = response.getStatusCode();
}
catch(ex) {
	var message = ex.message;
}