[ServiceNow] ERROR: Cannot find default value for object

Not Yet Reviewed

I'm having a really strange problem here as far as I can tell. I am building out some customization on top of the ServiceNow Integration which will run some checks and ultimately sync the manager of the group from MAX into the Default Shift of xMatters.

To do this, it first needs to grab the members from the default shift, because we only want to perform this action if the shift is empty. It will then use that response to run some logic checks and then proceed. However, I am getting hung up on the GET request. The thing that makes it strange is that the request is using 

var res = this.dataHelper.get(path);

The reason this is weird is because I put in a debugger into that actual function and was able to see the entire object response but for some reason its broken by the time it returns to the function which calls it. Below is a breakdown of my code along with the errors I am receiving.

 

xMattersGroupMembership (triggered when adding xMatters role to group)

(custom function) syncManagerToDefaultShift: function (groupName, manager_xm_id) {

var path = '/groups/' + encodeURIComponent(groupName) + '/shifts/Default Shift/members';
var res = this.dataHelper.get(path);

this.log.debug('*** DATA: ' + data);


It fails by the time it gets to the debugger, but in the actual dataHelper.get function, I can see that the response is valid.

 

Below is what the actual dataHelper function is followed by my debugging edit which shows me that the response is valid:

 

get: function (route, params) {
var path = this.baseURL + route;

if (params) {
for (var k in params) {
if (params.hasOwnProperty(k)) {
path += path.indexOf('?') === -1 ? '?' : '&';
path += encodeURIComponent(k) + '=' + encodeURIComponent(params[k]);
}
}
}

return this.sendRequest({
method: 'GET',
path: path
});
},
get: function (route, params) {
var path = this.baseURL + route;

if (params) {
for (var k in params) {
if (params.hasOwnProperty(k)) {
path += path.indexOf('?') === -1 ? '?' : '&';
path += encodeURIComponent(k) + '=' + encodeURIComponent(params[k]);
}
}
}

var res = this.sendRequest({method: 'GET', path: path)};

this.log.debug('**** ' + JSON.stringify(res));
},

 

Full Error 

[1562944661779 | xMLog-27c87b52]:
xMatters Group Sync BR: TypeError: Cannot find default value for object.
* fileName: sys_script_include.c8a205cb7b02f1008e0b707d784d4dbc.script
* sourceName: sys_script_include.c8a205cb7b02f1008e0b707d784d4dbc.script
* lineNumber: 131
* stack: at sys_script_include.c8a205cb7b02f1008e0b707d784d4dbc.script:131 (anonymous)
at sys_script_include.d6d8ed614f4712008472a88ca310c757.script:328 (anonymous)
at sys_script_include.d6d8ed614f4712008472a88ca310c757.script:124 (anonymous)
at sys_script.1fca1e074fb4c2008472a88ca310c700.script:25 (onAfter)
at sys_script.1fca1e074fb4c2008472a88ca310c700.script:1
at sys_ui_action.42da42d00a0a0b340066377beb6dd099.script:1

* rhinoException: TypeError: Cannot find default value for object. (sys_script_include.c8a205cb7b02f1008e0b707d784d4dbc.script; line 131)
0

Comments

6 comments
Date Votes

Please sign in to leave a comment.

  • I should also point out something else. In the logs inside of ServiceNow, the log for the GET request is nowhere to be found, only the error that calling that function failed which, again, is odd given that I was able to view the response from inside of the GET function itself.

    0
  • Hey MassMutual :D

       I have seen ServiceNow do weird things when it freaks out. Looking over the code, I do see a mis-matched } on this line:

    var res = this.sendRequest({method: 'GET', path: path)};

    The )} need to be swapped. I'm guessing that might just be a copy/paste issue, as I think you would have other problems. 

    Lemme take a deeper look and I'll post back. 

     

    0
  • Ok, couple things

    1. I think you might need to encode the space in "Default Shift". You can use the encodeURIComponent function or just insert a "%20". 
    2. I think your debug line is printing "data", not "res":
    var path = '/groups/' + encodeURIComponent(groupName) + '/shifts/Default Shift/members';
    var res = this.dataHelper.get(path); // "res"

    this.log.debug('*** DATA: ' + data); // "data"

    I'm guessing that's your problem as the code itself looks ok otherwise. 

    If it still fails, can you post the value of "path" before the sendRequest function? That's about all I can think might be funny. 

    Happy Friday!

    0
  • Ahh, yes that can be ignored. That wasn't me copy/pasting the code just re-writing it. That part was removed once I realized it wasn't breaking in that function specifically, so that datHelper.get() function is back to stock. 

    0
  • Wow, it was the encoding in the pathname for Default%20Shift that solved it. Thanks for that Travis! I quick followup, I have done requests like this a million times in both powershell and postman and never encodes the paths like that, were they just always doing it behind the scenes or is there something about the request coming from ServiceNow that makes this necessary for the request to succeed?

     

    Thanks again for all the help!!!

    0
  • Yea, interesting. Seems like they should at least give a better error message. This is the part that adds the "path" to the RESTMessage object inside the sendRequest function:

            var endpoint = (opts.endpoint ? opts.endpoint : hostname + opts.path);

    // Build the RESTMessage.
    var restMessage = new sn_ws.RESTMessageV2();

    // method enums are defined in lowercase
    restMessage.setHttpMethod(opts.method.toLowerCase());
    restMessage.setEndpoint(endpoint);

    So yea, take it up with ServiceNow :D

    Glad we got you moving. 

    Happy Friday!

    0

Didn't find what you were looking for?

New post