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  

In widget, when query table, I are not getting any value

Community Alums
Not applicable

Hi,

I am working on the widget, 

----------------------------------------------------------------
 server side code:-
(function() {
var gr=new GlideRecord('custom_table');
gr.addQuery('number','5f53XXXXXX1210446ef9XXXXXX');   //String type passing sys_id
gr.query();

if(gr.next()){
data.firstoption = gr.get_value('number');
}
})();


In HTML code:
<div>
{{data.firstoption}}

</div>

------------------------------------------------

Here, I am not any value in output, am I am missing any thing..??

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Community Alums  ,

 

I think you are querying it wrong.
In the query you need to set the sys_id and then later you can use gr.getValue(field_name).
Can you please try the below code-

 

(function() {
    var gr = new GlideRecord('custom_table');
    gr.addQuery('sys_id', '5f53XXXXXX1210446ef9XXXXXX');   //String type passing sys_id
    gr.query();
    
    if (gr.next()) {
        data.firstoption = gr.getValue('number');
        gs.info('Record found: ' + data.firstoption);
    } else {
        gs.info('No record found');
    }
})();

 

 

 

View solution in original post

1 REPLY 1

Community Alums
Not applicable

Hi @Community Alums  ,

 

I think you are querying it wrong.
In the query you need to set the sys_id and then later you can use gr.getValue(field_name).
Can you please try the below code-

 

(function() {
    var gr = new GlideRecord('custom_table');
    gr.addQuery('sys_id', '5f53XXXXXX1210446ef9XXXXXX');   //String type passing sys_id
    gr.query();
    
    if (gr.next()) {
        data.firstoption = gr.getValue('number');
        gs.info('Record found: ' + data.firstoption);
    } else {
        gs.info('No record found');
    }
})();