- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 09:23 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 09:54 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2015 09:54 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2015 03:16 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2015 05:47 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2015 12:04 AM
Thanks. Mine also resolved now. This code really helped a ton.