Service Portal : How to gliderecord in Widget?

kutvaram
Tera Expert

Hi All,

I want to gliderecord in service portal widget - client script. How to do that?

If I put like this as below,

var gr =new GlideRecord("incident");

gr.addQuery("active","=",'true');
gr.orderBy('number');
gr.query();
if(gr.next())
{
alert("hi");
alert("Total Rows:"+gr.getRowCount());
}

This is not working. How to achieve the same in Widget - Client Script? Please clarify.

Regards,
Ram

4 REPLIES 4

Omkar Mone
Mega Sage

Hi 

This is not happening in the client script. You can do the same in server script of the widget.

Do you want this to happen on initial load?

 

Then in server script do in !input block, something like this :-

 

if(!input)

{

var gr =new GlideRecord("incident");

gr.addQuery("active","=",'true');
gr.orderBy('number');
gr.query();
if(gr.next())
{
gs.addInfoMessage("hi");
gs.addInfoMessage("Total Rows:"+gr.getRowCount());
}

}

 

 

Regards,

Omkar Mone.

www.dxsherpa.com

Hi Omkar,

I want to do that gliderecord when a button is clicked.

How to do that in server script?

Thoughts?

Regards,

Ram

Hi 

Then when you click the button,

in the ng-click function on client script do something like this  ,

 

Client Script.

 

c.buttonClicked = function()

{

c.data.clicked= "clicked";

c.server.update();

}

 

Server Script :-

 

if(input.clicked)

{

//write your code here.

}

 

Regards,

Omkar Mone.

www.dxsherpa.com

Luca Torchetti1
ServiceNow Employee
ServiceNow Employee

Hello Ram,

on client side you need a callback when invoking a query function. Below an example

gr.query(response);

function response(result) {

                while(result.next()) {

...

                }

}

but I do NOT suggest to use GlideRecord in client side. Instead, use the $http to query objects by REST API, so you can take advantage of all the security model of the platform (ACL, etc...).

Hope this helped you. Please mark helpful in case.

Luca