Condition to Check for Item's Category on Approval

Sofija
Giga Expert

Hi All,

I have a scheduled job that runs daily to issue approval reminders for outstanding requested item approvals. I now want to split this job to issue one email notification for item's under Hardware category and other for all others.

The issue is that I can't seem to add a correct query to find outstanding approval for requested items where item's category is Hardware.

Queries that I tried and they did not work:

  1. appr.addQuery('sysapproval.ref_sc_req_item.cat_item.category.sys_id', 'e29b2cba0f594200a17bdd44e2050ef6');
  2. appr.addQuery('sysapproval.ref_sc_req_item.cat_item.category', 'e29b2cba0f594200a17bdd44e2050ef6');
  3. appr.addQuery('sysapproval.ref_sc_req_item.cat_item.category', 'Hardware');

Does anyone have any thoughts on what I'm missing here?

Thank you!!

Kamile

12 REPLIES 12

If you notice, I have not used the category while querying and using it inside while loop.


It works I know that, as it is active on my instance!


Sofija
Giga Expert

FYI - this is a script that I use for reminders. The line in bold is the one I am having trouble to make this job work. If I exclude it, the job works perfectly for all RITM approvals.



remindApprovers();


function remindApprovers(){


// remind everyone, all the time?


var spamMachine = false;



var appr = new GlideRecord('sysapproval_approver');


if (spamMachine){


  appr.addQuery('state', 'requested');


  appr.addQuery('sysapproval.sys_class_name', 'sc_req_item');


}


else {


  appr.addQuery('state', 'requested');


  appr.addQuery('sysapproval.sys_class_name', 'sc_req_item');


  appr.addQuery('sysapproval.cat_item.category', 'e29b2cba0f594200a17bdd44e2050ef6');


  appr.addQuery('sys_created_on', '>', gs.daysAgoStart(20));


  appr.addQuery('sys_created_on', '<', gs.daysAgoEnd(20));


}


appr.query();


while (appr.next()){


  gs.eventQueue("requestitem.itil.approve.reminderfnl.HSC", appr, gs.getUserID(), gs.getUserName());


  gs.log('Re-requested final approval of task ' + appr.sysapproval.number + " by " + appr.approver.name);


}


}


Sofija
Giga Expert

So I just ran some tests and actually the script I posted below is working just fine and using different notifications for a different category items. So no changes needed at all



Thank you everyone for help!