- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 03:28 PM
I am trying to send a REST message without having a Outbound REST message record. I am using #3 in this as a guide Scripting Outbound REST - ServiceNow Wiki
I have variables that need to be passed from the Request into this workflow and this is what I am doing in the Workflow
var Name = current.variables.vm_name;
var MEM = current.variables.vm_memoryMb;
var CPU = current.variables.vm_numVcpus;
ar restMessage = new sn_ws.RESTMessageV2();
restMessage.setBasicAuth("admin", "admin");
restMessage.setHttpMethod("post");
restMessage.setEndpoint("https://HostIP/gateway/services/rest/v1/vms/a8005786-07ab-4263-b065-98fc868ac6de");
restMessage.setRequestHeader("Content-Type", "application/json");
restMessage.setRequestHeader("Accept", "application/json");
restMessage.setMIDServer("midserver01");
restMessage.setRequestBody = ({"specList":[{"name":"Name","memoryMb":MEM,"numVcpus":CPU,"numCoresPerVcpu":1,"overrideNetworkConfig":true,"vmNics":[{"networkUuid":"8e06c992-7543-48f7-9380-51493b09317b"}]}]});
var response = restMessage.executeAsync();
The workflow executes with no errors but I never see anything happen on the other end and can't find where to look for the output of the script so I can see what if anything is being sent out.
Any help is appreciated.
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 04:42 PM
A few things:
- You're missing a 'v' at the start of line 4: var restMessage
- Try stringifying the Object body
- I think you have unwanted quotes around the Name variable in the body
- Log the response to see what it is
var Name = String(current.variables.vm_name);
var MEM = String(current.variables.vm_memoryMb);
var CPU = String(current.variables.vm_numVcpus);
var obj = {"specList":[{"name":Name,"memoryMb":MEM,"numVcpus":CPU,"numCoresPerVcpu":1,"overrideNetworkConfig":true,"vmNics":[{"networkUuid":"8e06c992-7543-48f7-9380-51493b09317b"}]}]};
var json = JSON.stringify(obj);
var rm, response, status, responseBody, errorMsg;
try {
rm = new sn_ws.RESTMessageV2();
rm.setEndpoint("https://HostIP/gateway/services/rest/v1/vms/a8005786-07ab-4263-b065-98fc868ac6de");
rm.setHttpMethod("post");
rm.setBasicAuth("admin", "admin");
rm.setRequestHeader("Content-Type", "application/json");
rm.setRequestHeader("Accept", "application/json");
rm.setMIDServer("midserver01");
rm.setRequestBody(json);
response = rm.execute();
status = response.getStatusCode();
responseBody = response.getBody();
errorMsg = response.haveError() ? response.getErrorMessage() : '';
} catch (ex) {
errorMsg = ex.getMessage();
status = '500';
}
gs.log('Response\nstatus: ' + status + '\nerrorMsg: ' + errorMsg + '\nresponseBody: ' + responseBody);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2016 04:42 PM
A few things:
- You're missing a 'v' at the start of line 4: var restMessage
- Try stringifying the Object body
- I think you have unwanted quotes around the Name variable in the body
- Log the response to see what it is
var Name = String(current.variables.vm_name);
var MEM = String(current.variables.vm_memoryMb);
var CPU = String(current.variables.vm_numVcpus);
var obj = {"specList":[{"name":Name,"memoryMb":MEM,"numVcpus":CPU,"numCoresPerVcpu":1,"overrideNetworkConfig":true,"vmNics":[{"networkUuid":"8e06c992-7543-48f7-9380-51493b09317b"}]}]};
var json = JSON.stringify(obj);
var rm, response, status, responseBody, errorMsg;
try {
rm = new sn_ws.RESTMessageV2();
rm.setEndpoint("https://HostIP/gateway/services/rest/v1/vms/a8005786-07ab-4263-b065-98fc868ac6de");
rm.setHttpMethod("post");
rm.setBasicAuth("admin", "admin");
rm.setRequestHeader("Content-Type", "application/json");
rm.setRequestHeader("Accept", "application/json");
rm.setMIDServer("midserver01");
rm.setRequestBody(json);
response = rm.execute();
status = response.getStatusCode();
responseBody = response.getBody();
errorMsg = response.haveError() ? response.getErrorMessage() : '';
} catch (ex) {
errorMsg = ex.getMessage();
status = '500';
}
gs.log('Response\nstatus: ' + status + '\nerrorMsg: ' + errorMsg + '\nresponseBody: ' + responseBody);