Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scripted REST Resource

madhusudanshett
Kilo Contributor

Hello Everyone

I have created the following Scripted REST Resource to get the information about Priority -1 Incidents:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

  var table = 'incident',

  result_arr = [],

  gr = new GlideRecord(table);

  gr.addQuery('priority', 1);

  gr.query();

  while (gr.next()) {

  var result = {};

  result.short_description = gr.short_description;

  result.number = gr.number;

  result.state = gr.state;

  result.opened_at = gr.opended_at;

  result.location = gr.location.getDisplayValue();

  result.email= gr.email;

  result_arr.push(result);

  }

  return {

  "Result":result_arr,

  };

})(request, response);

When I try to get the response in REST API Explorer , I get the following message:

{
  "result": "",
  "error": {
  "message": "Cannot map object",
  "detail": "Cannot map object Check logs for error trace or enable glide.rest.debug property to verify REST request processing"
  },
  "status": "failure"
}

Please assist me to resolve this issue.

Thanks in advance.

17 REPLIES 17

Hi



return {


  "Result":result_arr


  };



Also gives the same message.   "message": "Cannot map object",



Thank you


Did you try;



return result_arr;



???


Hi


It doesn't work with return result_arr;.



Thank you


Try to write "Result": ... as lowercase "result".


russell_miller
Kilo Guru

Hi Madhusudan,



Try -



result.location = gr.location.getDisplayValue().toString;



RM