The CreatorCon Call for Content is officially open! Get started here.

Regarding GlideRecord on Client side

darshan-pra
Tera Expert

The Below Onload Client script in executing on PDI here accessing data through Glide Record.  Is a expected behavior  , what should be ideal case for glide Record in client side  , is through error or provide output .

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   alert('hello');
   var test=new GlideRecord('incident');
   test.query();
   if(test.next())
   {
    alert('Found incident' +test.getValue('number'));
   }
   
}
1 ACCEPTED SOLUTION

@darshan-pra  it would work in Native UI but not in portal, scoped app or mobile as mentioned by @Ankur Bawiskar

The GlideRecord API is the primary means of interfacing with the database on the server-side code. Its best not to mix server side APIs with client scripts as it could break in Service Portal, mobile and future upgrades. Use best practices so that your code is scalable and optimised. ServiceNow has GlideAjax class to call server side script from client side and fetch necessary data, you can make use of it.

Docs: https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

 

https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

 

Regards,

Ehab Pilloor

 

View solution in original post

6 REPLIES 6

Ehab Pilloor
Mega Sage

Hi @darshan-pra,

 

Your script is using server-side GlideRecord in a client script, which is not recommended in ServiceNow. Best practice is to avoid using GlideRecord directly in client scripts because it runs on the server. Instead, use GlideAjax to call a Script Include on the server from your client script. This way you can safely retrieve server side data like Incident records while keeping the client and server logic separated.

 

Regards,

Ehab Pilloor

That but here i am getting result without throwing any error  

@darshan-pra  it would work in Native UI but not in portal, scoped app or mobile as mentioned by @Ankur Bawiskar

The GlideRecord API is the primary means of interfacing with the database on the server-side code. Its best not to mix server side APIs with client scripts as it could break in Service Portal, mobile and future upgrades. Use best practices so that your code is scalable and optimised. ServiceNow has GlideAjax class to call server side script from client side and fetch necessary data, you can make use of it.

Docs: https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

 

https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

 

Regards,

Ehab Pilloor

 

Ankur Bawiskar
Tera Patron
Tera Patron

@darshan-pra 

you can use GlideRecord in client side but it's not recommended.

It won't work in portal and scoped app as it's not allowed

Also GlideRecord on client side has some limitations and not all methods can be used.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader