Get record on a Service Portal Widget via client script

jotasolano
Kilo Contributor

Hello,

I am new to SN and have been trying to get a GlideRecord to display as an alert using an HTML Widget on a Service Portal widget.

I was successfully able to load the record, but I get an error message on my console that tells me that I need to use a callback function. I have not been able to correctly create this callback function.

This is my script:

function text() {

  var res = new GlideRecord('incident');

  res.addQuery('number', 'INC0000001');

  res.query(getCallback);

}

function getCallback(res) {

  if(res.next()){

  var shortDescription = res.short_description.getDisplayValue();

  alert(shortDescription);

  } else {

  console.log("not working")

  }

}

text();

I get this error:

Uncaught (in promise) TypeError: Cannot read property 'records' of undefined(…)

at js_includes_sp.jsx?v=04-21-2016_1541&lp=Thu_May_19_12_55_41_PDT_2016&c=2_42:64344

What am I doing wrong?

Thanks for the help!

1 ACCEPTED SOLUTION

nathanfirth
Tera Guru

I would suggest you do your GlideRecord query using server script. Widgets in Service Portal are run as an Angular directive (scoped) so I'm not sure if some of the typical ServiceNow client scripts will run as expected.



Take a look at the widget "Hello World 3", it shows how to call the server script from the client script.


View solution in original post

6 REPLIES 6

Excellent. Thank you.


Hello


where is HEllo world 3 widget?


stephane