How can I query for records associated with a Certification Task?

demohr
Kilo Expert

I'm trying to write a business rule to update a value on a record based on when the certification task associated with that record was closed. However, it doesn't look like there's any sort of relationship that I can find between Cert Tasks and the (in this case custom) table where the Certification Elements reside such that I can dot walk it.

How would I find all of the records associated with a particular Certification Task in a script?

1 ACCEPTED SOLUTION

demohr
Kilo Expert

I figured this out and I wanted to share my solution, since it wasn't obvious.



The Certification Element table has a reference to the Certification Task and the "Document" which is really a reference to whatever record you're certifying. Using that, I was able to write a script to update my values like this:



function updateAccounts() {


  var arrayUtil = new ArrayUtil();


  var myTaskID = current.sys_id;


  var docIDs = [];



  var myEl = new GlideRecord("cert_element");


  myEl.addQuery("cert_task",myTaskID);


  myEl.query();



  while(myEl.next()){


  docIDs.push(myEl.id.toString());


  }


  gs.print(arrayUtil.unique(docIDs));



  var myExAct = new GlideRecord("u_external_accounts");


  myExAct.addEncodedQuery("sys_idIN" + docIDs);


  myExAct.query();



  while(myExAct.next()){


  var gdt = new GlideDateTime(myExAct.u_next_expiration);


  gdt.addDaysLocalTime(myExAct.u_expiration_period);


  myExAct.u_next_expiration = gdt;


  myExAct.update();


  }


}




updateAccounts();


View solution in original post

4 REPLIES 4

demohr
Kilo Expert

I figured this out and I wanted to share my solution, since it wasn't obvious.



The Certification Element table has a reference to the Certification Task and the "Document" which is really a reference to whatever record you're certifying. Using that, I was able to write a script to update my values like this:



function updateAccounts() {


  var arrayUtil = new ArrayUtil();


  var myTaskID = current.sys_id;


  var docIDs = [];



  var myEl = new GlideRecord("cert_element");


  myEl.addQuery("cert_task",myTaskID);


  myEl.query();



  while(myEl.next()){


  docIDs.push(myEl.id.toString());


  }


  gs.print(arrayUtil.unique(docIDs));



  var myExAct = new GlideRecord("u_external_accounts");


  myExAct.addEncodedQuery("sys_idIN" + docIDs);


  myExAct.query();



  while(myExAct.next()){


  var gdt = new GlideDateTime(myExAct.u_next_expiration);


  gdt.addDaysLocalTime(myExAct.u_expiration_period);


  myExAct.u_next_expiration = gdt;


  myExAct.update();


  }


}




updateAccounts();


Hi Dennis,



This is helpful really I have the same requirement. When ever the certification task is closed, I want the associated records state should be updated , In my case Incidents associated with certification task. But can you please clarify few points:


1. BR should be written for certification_element table?


2. Where are you checking the condition that your certification task is closed?



my requirement is as simple as : when certification task is closed, all incident's state should be updated to resolved.



Please help.


Thanks


I wrote that BR for the Certification Task table and used the condition that the task was Closed Complete and the Short Summary matched the type I was looking for.


Thanks. Mine also resolved now. This code really helped a ton.