- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2017 04:06 AM
Hi everyone,
Please help!
Even though in the scheduled job "Control attestation nightly run" which runs daily at 00:00:00 hours, according to it, the controls in review/monitor state should return to attest state as per the frequency set. It is the OOTB(Out of the Box) functionality. But, currently it's not happening and the state of the control is not getting changed.
The script in the scheduled job is :
var control = new GlideRecord("sn_compliance_control");
control.addQuery('state', 'IN', 'review,monitor');
control.query();
var now = new GlideDateTime();
while(control.next()) {
// Get the time of the last attestation
var attestationQ = new GlideRecord('asmt_assessment_instance_question');
attestationQ.addQuery('source_id', control.getUniqueValue());
attestationQ.orderByDesc('sys_updated_on');
attestationQ.query();
if(attestationQ.next()) {
var frequency = control.profile.attestation_frequency + '';
var lastAttested = new GlideDateTime(attestationQ.sys_updated_on + '');
switch(frequency) {
case 'daily':
lastAttested.addDaysUTC(1);
break;
case 'weekly':
lastAttested.addWeeksUTC(1);
break;
case 'monthly':
lastAttested.addMonthsUTC(1);
break;
case 'quarterly':
lastAttested.addMonthsUTC(3);
break;
case 'semi_annually':
lastAttested.addMonthsUTC(6);
break;
case 'annually':
lastAttested.addYearsUTC(1);
}
if(now >= lastAttested) {
control.state = 'attest';
control.update();
}
}
}
But the controls having frequency "daily" and in review/monitor state are not changing back to "attest" state after the execution of the scheduled job.
Please help and share anything that is needed more to accomplish this.
Regards,
Avijeet
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 05:10 AM
Hi Avijeet,
I had the same question and I believe I have found out what is happening.
If you look at the script you will see that when it checks the frequency it is not checking the 'frequency' of the control, but rather the 'attestation_frequency' of the profile.
By changing this line:
var frequency = control.profile.attestation_frequency + '';
To:
var frequency = control.frequency + '';
It should now set the control to attest based on the frequency of the control.
I have added 2 screenshots to show you the field on the Control form and on the Profile form.
Profile Form: Note the Attestation Frequency field.
Control Form: Note the Frequency field.
I have raised a HI ticket with ServiceNow asking if this is intended behaviour and will update this post when I get a response.
Regards,
Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2017 06:17 AM
hi,
Can you please try putting logs into scheduled job and see what is values of now and lastAttested is populating, also with the print the output of the condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 05:10 AM
Hi Avijeet,
I had the same question and I believe I have found out what is happening.
If you look at the script you will see that when it checks the frequency it is not checking the 'frequency' of the control, but rather the 'attestation_frequency' of the profile.
By changing this line:
var frequency = control.profile.attestation_frequency + '';
To:
var frequency = control.frequency + '';
It should now set the control to attest based on the frequency of the control.
I have added 2 screenshots to show you the field on the Control form and on the Profile form.
Profile Form: Note the Attestation Frequency field.
Control Form: Note the Frequency field.
I have raised a HI ticket with ServiceNow asking if this is intended behaviour and will update this post when I get a response.
Regards,
Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 06:04 AM
Thank you, Graham, for the help at such short notice.
Yes please. A confirmation from the servicenow product team would definitely clarify it further.
Regards,
Avijeet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 08:06 AM
Hi Avijeet,
This was the response I got from ServiceNow,
As per the Scheduled Script Execution - Control attestation nightly run, it was coded in such way that it's taking the attestation frequency from the profile of the control and based on which it's attesting the state of the control. Yes, this is the intended behaviour of the Scheduled job. If you still want to change it to run based on the control frequency, you can make the modifications accordingly.
So now we know!
Regards,
Graham