Scripted Audit and Follow On Tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2019 01:55 AM
Hi,
I'm playing around with Scripted Audits.
Hard to find any detailed documentation/examples how to do this, but using the commented example:
/////////////////////////////////////////////////////
/// This script works with Data Center Zones filter //
/////////////////////////////////////////////////////
var desiredFloorSpaceUsage = 30; // Value to audit against
var assignToUser = '46d44a23a9fe19810012d100cca80666'; // Beth Anglin
var assignToGroup = '8a5055c9c61122780043563ef53438e3'; // Hardware group
var taskMsg = 'See the audit results below for the discrepancies that must be addressed';
// API call to retrieve records based on the filter
var gr = new SNC.CertificationProcessing().getFilterRecords(current.filter);
// Loop over all records defined by the filter
while(gr.next()) {
var sysId = gr.getValue('sys_id'); // Sys ID of audited record
var floorSpaceInUse = gr.getValue('floor_space_in_use'); // Value to audit
// Determine if certification condition passes or fails
if (floorSpaceInUse < desiredFloorSpaceUsage) {
var columnNameSpace = gr.floor_space_in_use.getLabel(); // String value of column audited against
// Call create Follow on Task API and save the returned sys_id for use in logging audit result fail
// Params:
// auditId - Sys id of the audit record executed
// ciId Sys - id of the configuration item. Empty string if not a cmdb ci
// assignedTo - Sys id of user to assign task to. Can be empty
// assignmentGroup - Sys id of group to assign task to. Can be empty
// shortDescr - Short description for the Follow On Task. Can be empty
// Return value: Sys id of the created follow on task
var followOnTask = new SNC.CertificationProcessing().createFollowOnTask(current.sys_id, sysId, assignToUser, '', taskMsg);
// Call log failed result API
// Params:
// auditId - Sys id of audit record executed
// auditedRecordId - Sys id of the record audited
// followOnTask - Sys id of the follow on task associated with the audited record(@see auditedRecordId). Can be empty
// columnDisplayName - Label of the column audited(ex. Disk space (GB)). Can be empty
// operatorLabel - Label of the operator used to audit the column(ex. is not empty, greater than). Can be empty
// desiredValue - Desired value of the column. Can be empty
// discrepancyValue - Discrepancy value. Can be empty
// isCI - True, if audited record is a CI. False, otherwise.
// domainToUse - Sys domain of the "cert_audit" record. Can be empty
new SNC.CertificationProcessing().logAuditResultFail(current.sys_id, sysId, followOnTask, columnNameSpace, 'greater than', desiredFloorSpaceUsage, floorSpaceInUse, true);
} else { // If certification condition pass, write a Audit Result Pass via API
// Params:
// auditId - Sys id of audit record executed
// auditedRecordId - Sys id of the record audited
// isCI - True, if audited record is a CI. False, otherwise. Can be empty.
// domainToUse - Sys domain of the "cert_audit" record. Can be empty.
new SNC.CertificationProcessing().logAuditResultPass(current.sys_id, sysId, true);
}
}
*/
I'm able to create some Audit Results.
But how do I avoid the Follow On Tasks being created in table cert_follow_on_task ?
Even if this is not checked:
It creates a record in cert_follow_on_task for each record the script checks.
And even if I remove the 3rd parameter for the followOnTask:
Like this:
It creates the records in cert_follow_on_task.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2020 06:53 AM
After revisiting this and finally having time to really read through the script logic, it became quite clear that if we don't want tasks we had to do two things:
(Using the OOB sample)
Comment out the createFollowOnTask method, or just don't include it altogether.
//var followOnTask = new SNC.CertificationProcessing().createFollowOnTask(current.sys_id, sysId, assignToUser, '', taskMsg);
AND make the followOnTask parameter blank in the logAuditResultFail method.
new SNC.CertificationProcessing().logAuditResultFail(current.sys_id, sysId, '', columnNameSpace, 'greater than', desiredFloorSpaceUsage, floorSpaceInUse, true);
The OOB sample has the variable called followOnTask in the parameter called followOnTask, which I think was a bit confusing. So then, the logAuditResultFail method would stop auditing when the first failure was encountered because there was no task returned when one was expected. Making this parameter blank relieves this issue and allows the audit to continue and log failures without making tasks.
So we prevent a task from being created, but we still get some audit result from our evaluation.
Hope this helps anyone who ends up here!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 07:48 PM
Hey! I was wondering if you have found a way to create tasks only if there are no existing tasks that were created for the same audit result?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2023 06:41 AM
Hi @Von Naval
For now this is just an idea but I guess you can script everything in the audit script code, including search for an existing task and creating a new one only if there is no previous one... I will try implementing this and reply here with my findings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2023 06:38 AM
Hi @ggarcia1 , thanks for clarifying the topic!
I did scripted audits before without creating tasks (I did not use the sample code directly hence did not stumble upon the problem you had) but now I want to add tasks. I first tried to use the settings available on the form:
But it did not created any tasks.
I guess the options on the form are only to mislead people for Scripted audits and I will need to code the whole logic but just in case I missed anything...
Thank you in advance!