Ajay_Chavan
Kilo Sage

Set Up REST User

  1. From the ServiceNow instance, navigate to User Administration > Users.
  2. Click New.
  3. Fill in the following:
    • User ID
    • Password
    • First name: The user's first name.
    • Last name: The user's last name.
  1. Right-click the header and select Save.
  2. Under the Roles related list, click Edit.
  3. Move all REST related roles and web service admin role from the Collection list to the Roles List.
  4. Click Save.

 

Use Case

Create an Change Request in Service Now instance (Instance 1) and auto creates Change in target service now instance (Instance 2)

Steps

  • In Instance 2,Navigate to REST API Explorer
  • Select Namespace as "now" and Method as "Post"
  • Select table as "Change Request"
  • Navigate down and click on any script like Perl, python, ruby etc
  • Copy the URL from the script
  • Copy the REST API
  • Consume copied REST API URL in Instance 1 in REST Message
  • Provide the Name, End Points path and Credential(Created in Set Up REST User)
  • Add HTTP Header for REST Message
  • Accept: application/json
  • Content-Type: application/json

and save the record

  • Navigate to Post Operation. Provide credentials and add header  and Save
  • Add the field mapping in the content field

{'short_description':'${short_desc}','category':'${cat}'}

  • Click on Auto Generate Variable Related Links
  • Add values to the variables post creation
  • Click on "Preview Script Usage"
  • Copy the code
  • Create an After Business Rule in Instance 2
  • Select Table as "Change Request"
  • Select After Insert Operation
  • Then navigate to script and add the code
    (function executeRule(current, previous /*null when async*/) {
    
    
    
    try {
    
    var r = new sn_ws.RESTMessageV2('Incident Integration Test', 'post');
    
    r.setStringParameter('cat', current.category);
    
    r.setStringParameter('short_desc', current.category + 'is not working' );
    
    
    
    //override authentication profile
    
    //authentication type ='basic'/ 'oauth2'
    
    //r.setAuthentication(authentication type, profile name);
    
    
    
    var response = r.execute();
    
    var responseBody = response.getBody();
    
    var httpStatus = response.getStatusCode();
    
    }
    
    catch(ex) {
    
    var message = ex.getMessage();
    
    }
    
    
    
    })(current, previous);

 

  • Then create a Change in Instance 2
  • And check a new change request would be created in Instance 1
Version history
Last update:
‎09-26-2019 03:48 AM
Updated by: