Dot-Walking within GlideRecord

Mussie
ServiceNow Employee
ServiceNow Employee

Hi Guys,

I need to do a dot-walking within the below GlideRecord, I know I need to use getElementValue() but I have no idea how to use it. My requirement is in addition to the below condition, I also want to have the below query added:

sysapproval.cat_item==gs.getProperty('snc.eprocurement.catalog_item')

The below query runs for all catalog items but I only wanted to run for one specific catalog item:

var gr = new GlideRecord('sysapproval_approver');

gr.addEncodedQuery('sys_created_onRELATIVEGE@dayofweek@ago@4^sys_created_onRELATIVELT@dayofweek@ago@3^state=requested^source_table=sc_req_item');

gr.query();

while(gr.next()){

  gs.eventQueue("eproc_approval.reminders_3days", gr, gs.getUserID(), gs.getUserName());

}

Any idea?

Mussie

1 ACCEPTED SOLUTION

Geoffrey2
ServiceNow Employee
ServiceNow Employee

Oh, the issue is that you can't dot-walk to cat_item (on the sc_req_item table) from the sysapproval field (which points to the task table).



Try one of these.



var query = 'sys_created_onRELATIVEGE@dayofweek@ago@4^sys_created_onRELATIVELT@dayofweek@ago@3^state=requested^source_table=sc_req_item';


var appr = new GlideRecord('sysapproval_approver');


appr.addEncodedQuery(query);


appr.query();


while (appr.next()){


      if (appr.getElement('sysapproval.cat_item') == gs.getProperty('snc.eprocurement.catalog_item'))


              gs.eventQueue("eproc_approval.reminders_3days", appr, gs.getUserID(), gs.getUserName());


}



var query = 'sys_created_onRELATIVEGE@dayofweek@ago@4^sys_created_onRELATIVELT@dayofweek@ago@3^state=requested^source_table=sc_req_item';


var appr = new GlideRecord('sysapproval_approver');


appr.addEncodedQuery(query);


appr.query();


while (appr.next()){


        var ritm = new GlideRecord('sc_req_item');


        if (ritm.get(appr.sysapproval)) {


                if (ritm.cat_item == gs.getProperty('snc.eprocurement.catalog_item'))


                        gs.eventQueue("eproc_approval.reminders_3days", appr, gs.getUserID(), gs.getUserName());


        }


}


View solution in original post

8 REPLIES 8

only we can use that table name field in add query   gr.addQuerty('glide_recird_field_name', 'value');   // this field_name refering to only that table...


so, the best option is to use the view itself



Hope you got it.


Geoffrey2
ServiceNow Employee
ServiceNow Employee

var query = 'sys_created_onRELATIVEGE@dayofweek@ago@4^sys_created_onRELATIVELT@dayofweek@ago@3^state=requested^source_table=sc_req_item';


query += '^sysapproval.cat_item=' + gs.getProperty('snc.eprocurement.catalog_item');



var gr = new GlideRecord('sysapproval_approver');


gr.addEncodedQuery(query);


gr.query();


while (gr.next()){


      gs.eventQueue("eproc_approval.reminders_3days", gr, gs.getUserID(), gs.getUserName());


}


Geoffrey2
ServiceNow Employee
ServiceNow Employee

Oh, the issue is that you can't dot-walk to cat_item (on the sc_req_item table) from the sysapproval field (which points to the task table).



Try one of these.



var query = 'sys_created_onRELATIVEGE@dayofweek@ago@4^sys_created_onRELATIVELT@dayofweek@ago@3^state=requested^source_table=sc_req_item';


var appr = new GlideRecord('sysapproval_approver');


appr.addEncodedQuery(query);


appr.query();


while (appr.next()){


      if (appr.getElement('sysapproval.cat_item') == gs.getProperty('snc.eprocurement.catalog_item'))


              gs.eventQueue("eproc_approval.reminders_3days", appr, gs.getUserID(), gs.getUserName());


}



var query = 'sys_created_onRELATIVEGE@dayofweek@ago@4^sys_created_onRELATIVELT@dayofweek@ago@3^state=requested^source_table=sc_req_item';


var appr = new GlideRecord('sysapproval_approver');


appr.addEncodedQuery(query);


appr.query();


while (appr.next()){


        var ritm = new GlideRecord('sc_req_item');


        if (ritm.get(appr.sysapproval)) {


                if (ritm.cat_item == gs.getProperty('snc.eprocurement.catalog_item'))


                        gs.eventQueue("eproc_approval.reminders_3days", appr, gs.getUserID(), gs.getUserName());


        }


}


Mussie
ServiceNow Employee
ServiceNow Employee

Thanks Geoff, the first one worked.