Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
Outbound REST calls via mid server not working from Scripts, script background and returns null response - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • Outbound REST calls via mid server not working from Scripts, script background and returns null response
KB0550022

Outbound REST calls via mid server not working from Scripts, script background and returns null response


1918 Views Last updated : Apr 7, 2024 public Copy Permalink
KB Summary by Now Assist

Issue

Outbound REST calls via mid server not working from scripts, script background and returns null response

 

Problem
Outbound REST calls through the Mid Server are not working from scripts, script background and returns null response.

 

 

Symptoms
For example: Here is a REST call script with a GET function executed thought the MID Server:

var r = new RESTMessage('XYZ Organization', 'get');
r.setStringParameter('XYZ_host', '123.123.123.123');
r.setStringParameter('org_id', '4');
var response = r.execute();
These are the symptoms:
  • The Test (Related Link) always works successfully.
  • The previewed script, pasted into a Background Script never works – the response value is always null.
  • In addition, the previewed script pasted into a script include and used by a scheduled job never works – the response value is always null.

  

Cause
When using the Mid Server, the script executed from background or business rule/script does not wait for an response, hence the response is null.
Resolution
The REST call has to be modified like below to wait and get the response when executed from scripts, background scripts, or business rules. 


var r = new RESTMessage('XYZ Organization', 'get');
r.setStringParameter('XYZ_host', '123.123.123.123');
r.setStringParameter('org_id', '4');
var response = r.execute();
var k = 1; 
while ( response == null ) { 
gs.print( "waiting ... " + k + " seconds" ); 
response = r.getResponse( 1000 ); 
k++; 

if ( k > 30 ) { 
gs.print( 'service time-out' ); 
break; // service did not respond after 30 tries 
} 
} 
gs.print( "RESPONSE: " + response ); 
if ( response != null ) { 
gs.print( 'body=' + response.getBody() ); 
} 


The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.