Populate a field by DOT-WALK via REST

mballinger
Mega Guru

Hello,

We have a requirement to create an incident record on another ServiceNow instance and populate the Caller using a user_id via REST Integration. We are using the user_id because the sys_id's in both instances do not match up. Also, we cannot send over the name because there could be multiples. The user_id is a unique identifier, but I am having issues sending in the script. Currently, we are able to create the Incident Record with our current payload but dot-walking seems to be an issue.

 

The REST is currently triggered via a Business Rule. When the Business Rule is triggered, a call is made to a script include where the execution of the REST occurs. When I try to dot-walk it breaks and the Incident record in the other instance is not created.

 

This is what I have:

createIncident: function(current) {
   var user_id = current.u_submitter.user_id;
   var description = current.u_description;
   var state = current.u_state;

   var result = this.sendRequest(user_id, description, state);
}

sendRequest: function(user_id, description, state) {
   try {
      var r = new sn_ws.RESTMessageV2('createIncident', 'Create/Update');
      var json = {};

      json.caller_id.u_user_id = user_id;
      json.description = description;
      json.state = state;
      
      var strJSON = JSON.stringify(json);

      r.setRequestBody(strJSON);
      var response = r.execute();
      var responseBody = response.getBody();
      var httpStatus = response.getStatusCode();  
    
   } catch(ex) {
      var message = ex.message;
      gs.error("Error in Incident Creation " + message, "Incident Integration");
   }
 
}

 

Again the only piece that is not working is the population of the caller_id when using the dot-walk. Variables and definitions are all working fine. I am not an admin on that side so troubleshooting is a little difficult.

 

Anything helps!

 

Thanks!

1 ACCEPTED SOLUTION

Yes, that would be how I would configure.

View solution in original post

5 REPLIES 5

Tony Chatfield1
Kilo Patron

Hi, I don't think you can dot.walk in the manner you are trying (except for GET) as there is no direct link\the related record does not exist.  Either the target platform would need to lookup and map the user_id you passed in,

or you could first GET the correct sys_user.sys_id  based on user_id, and then use this sys_id in your POST. 

Thanks for your response! So I would need to use a get method passing the user_id, return the sys_id back to my instance, and then set the value back on the ITSM instance?

Yes, that would be how I would configure.

ricker
Tera Guru

@mballinger,

Is this BR running on the Incident table?  Is u_submitter a valid reference field?  Are u_description and u_state valid field?  OOB Incident fields would be caller_id, description, state.  When you’re creating your JSON object just do one level json.user_id or json.caller_id.