How to delete Cancelled Survey Instances?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 04:44 AM
Hi everyone,
I have a scheduled job that looks for any survey instances older than 7 days and cancel them if they are in the status Ready to take. The Scheduled job script can be seen below.
autoCancelassessments();
function autoCancelassessments() {
var value = gs.getProperty('glide.assessment.autoclose.time'); // create a system property in sys_properties table., Type = integer and value = 7 in
var valueinInt = parseInt(value);
if (valueinInt > 0) {
var gr = new GlideRecord('asmt_assessment_instance'); // query the table
var other = gr.addQuery('metric_type', '277b148b4f5106007825b3318110c796');
other.addOrCondition('metric_type', '8c3a2c44d7211100158ba6859e6103fe');
other.addOrCondition('metric_type', '87186844d7211100158ba6859e610378');
other.addOrCondition('metric_type', '502a2c44d7211100158ba6859e6103a3');
other.addOrCondition('metric_type', '6826bdbf4fa54a40acbe01b28110c762');//edit your assessment names
gr.addQuery('state', 'ready');
gr.addQuery('sys_created_on', '<', gs.daysAgoStart(7));
gr.query();
while(gr.next()) {
gr.state = 'canceled'; //value of cancelled state.
gr.active = false;
gr.update();
}
}
}
In addition to cancel the survey instance I would also like to delete the once Cancelled Survey Instance. I found some helpful script in the OOTB scheduled job "Remove Old Assessment Data" but this is deleting all survey instances not just the cancelled ones. The Remove Old Assessment Data schedule job script can be seen below. I am now wondering how to combine there 2 scripts and have a single one which cancel the survey instances older than 7 days and then immediately deletes the survey instance as well. Any ideas?
var gdt = new GlideDateTime();
gdt.addYears(-1);
var gr = new GlideRecord("asmt_assessment_instance_question");
gr.addQuery("instance.assessment_group.sys_created_on", "<", gdt);
gr.query();
while (gr.next())
gr.deleteRecord();
var gr = new GlideRecord("asmt_assessment_instance");
gr.addQuery("assessment_group.sys_created_on", "<", gdt);
gr.query();
while (gr.next())
gr.deleteRecord();
var gr = new GlideRecord("asmt_metric_result");
gr.addQuery("assessment_group.sys_created_on", "<", gdt);
gr.query();
while (gr.next())
gr.deleteRecord();
Thanks,
Bogdan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 05:24 AM
Bogdan,
Were you able to get this working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 06:33 AM
Hi Tonya,
The cancellation part, yes I got it to work just fine but not the deletion one. If you need assistance with the cancellation part I would be happy to share the script i used to make it work. Just let me know if this is the case.
Thanks,
Bogdan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 04:25 AM
Hi Bodgan,
Can you please share the cancelled script?
thanks,
Kamal