Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

GlideRecord Query

huangh
Tera Contributor

Hi Developer,

I am running a GlideRecord Query in widget Service script . through the gs.info() i can see the data in session log . but i can not see the data in the html .

Can GlideRecord be used in widget service script?

var item = new GlideRecord('xxxx')
item.addQuery('number','xxxxxxxxx'); 
item.query(); 
data.testNext = item.next()
data.testData = item.short_description
gs.info(item.short_description)

 

 

1 ACCEPTED SOLUTION

ersureshbe
Giga Sage
Giga Sage

Hi, Can you try with alert or gs.addInfoMessage(); instead of gs.info(). 

Additionally, refer below code and it's similar to your case.  Refer the link with your instance for OOB widget and check Server Script area.

https://Instancename.service-now.com/now/nav/ui/classic/params/target/sp_widget.do%3Fsys_id%3D5c760f...

 

Sample Script:

    options.table = 'sn_customerservice_case';
    options.display_field = "short_description";
    options.show_secondary_fields_label = 'true';
    options.secondary_fields = "product,number";
    options.hide_header = false;
    options.hide_footer = true;
    options.maximum_entries = 5;
    options.always_show = 'true';
    //showing only open cases
    if(input && !gs.nil(input.contactId)){
        var cr= new GlideRecord('customer_contact');
      cr.addQuery('sys_id',input.contactId);
      cr.query();
    while(cr.next()){
        data.account=cr.account;
    }
Regards,
Suresh.

View solution in original post

1 REPLY 1

ersureshbe
Giga Sage
Giga Sage

Hi, Can you try with alert or gs.addInfoMessage(); instead of gs.info(). 

Additionally, refer below code and it's similar to your case.  Refer the link with your instance for OOB widget and check Server Script area.

https://Instancename.service-now.com/now/nav/ui/classic/params/target/sp_widget.do%3Fsys_id%3D5c760f...

 

Sample Script:

    options.table = 'sn_customerservice_case';
    options.display_field = "short_description";
    options.show_secondary_fields_label = 'true';
    options.secondary_fields = "product,number";
    options.hide_header = false;
    options.hide_footer = true;
    options.maximum_entries = 5;
    options.always_show = 'true';
    //showing only open cases
    if(input && !gs.nil(input.contactId)){
        var cr= new GlideRecord('customer_contact');
      cr.addQuery('sys_id',input.contactId);
      cr.query();
    while(cr.next()){
        data.account=cr.account;
    }
Regards,
Suresh.