Dot-Walking within GlideRecord

Mussie
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

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

ms_akila
Mega Expert

Hi ,



Add this line in 1st line of code



sysapproval.cat_item==gs.getProperty('snc.eprocurement.catalog_item')   and add this code below this line


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.addQuery('target_field_name',sysapproval.cat_item);// target field field is ur catalog item field name


gr.query();  


while(gr.next()){  


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


}


Mussie
ServiceNow Employee

Hi Akila,



Thanks for your response, you said 'target field is your catalog item field name'. How can I add a field into that query that doesn't exist in the table that I am querying?


The field name I am after is cat_item and is found in sc_req_item but I am querying the table sysapproval_approver. Could you please clarify?



Mussie


Dont make the code very complex..just create one view ..and join two tables then query the join table


Mussie
ServiceNow Employee

Thanks for the suggestion, I am aware of the fact that I can achieve this using a view but I wanted to check whether this is possible with the way I described it.


Mussie