I need to add dynamic url of the customer instances in business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 08:35 AM
Hi,
I am using below script for Incident rest Api in the business rule. The script is working but I need to set the url dynamically as we have so many Servicenow client instances where we need to create a incident.
Please anyone help me how I can set the endpoint of the client instance url dynamically.
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://xxxx.service-now.com/api/now/table/incident');
request.setHttpMethod('POST');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'name';
var password = 'pswd';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody("{\"short_description\":\"Hi\",\"assigned_to\":\"B\"}");
var response = request.execute();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 08:41 AM
Hi,
Try this script -
var instanceURL = gs.getProperty('glide.servlet.uri');
var endPoint_URL = instanceURL+ 'api/now/table/incident';
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(endPoint_URL);
request.setHttpMethod('POST');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'name';
var password = 'pswd';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody("{\"short_description\":\"Hi\",\"assigned_to\":\"B\"}");
var response = request.execute();
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 09:01 PM
HI
This code is in my developer instance but I need the url of the client instance. How will i get that, can you please suggest.
Thanks,
Revathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 10:12 PM
Hi
If you see my previous response/reply. line no-1 gives you instance url
example - https://instance_name.service-now.com
var instanceURL = gs.getProperty('glide.servlet.uri');
/* this property will gives you the dynamic instance url through/in which this script will be executed. */
try this script in your client's development instance. you will get dev instance url.
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 08:48 AM
Hi,
By default, the instance uses a relative URL which means you can avoid the base url and just specify the relative path. e.g. /api/now/table/incident
var endPoint_URL = '/api/now/table/incident';
Also, you can use the property that dynamically pulls the instance url.
var instanceURL = gs.getProperty('glide.servlet.uri'); // dynamically gets the instance base url
var endPoint_URL = instanceURL+ 'api/now/table/incident';
Regards,
Muhammad
Muhammad