- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 12:06 AM
I have had a request from our Servicedesk to remove or hide Assessment Instances records for a specific year we went live with surveys this year but records created prior to going live are appearing.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 12:27 AM - edited 04-16-2024 12:31 AM
Hi @Ralton Stewart ,
You can use Background scripts to delete assessment records meeting specific criteria. You can define these criteria within an encoded query and leverage the GlideRecord class's deleteMultiple method to permanently remove the selected records.
Below is the script where it s deleting assessment record from specific time period
// Create a GlideRecord object for 'asmt_assessment_instance' table
var assessmentGR = new GlideRecord('asmt_assessment_instance');
// Define the query for specific time in which you have to delete records
assessmentGR.addEncodedQuery('sys_created_onONOne year ago@javascript:gs.beginningOfOneYearAgo()@javascript:gs.endOfOneYearAgo()');
// Execute the query to retrieve matching records
assessmentGR.query();
// Loop through each retrieved record and delete it
while (assessmentGR.next()) {
assessmentGR.deleteRecord(); // Use deleteRecord() for clarity
}
If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 12:27 AM - edited 04-16-2024 12:31 AM
Hi @Ralton Stewart ,
You can use Background scripts to delete assessment records meeting specific criteria. You can define these criteria within an encoded query and leverage the GlideRecord class's deleteMultiple method to permanently remove the selected records.
Below is the script where it s deleting assessment record from specific time period
// Create a GlideRecord object for 'asmt_assessment_instance' table
var assessmentGR = new GlideRecord('asmt_assessment_instance');
// Define the query for specific time in which you have to delete records
assessmentGR.addEncodedQuery('sys_created_onONOne year ago@javascript:gs.beginningOfOneYearAgo()@javascript:gs.endOfOneYearAgo()');
// Execute the query to retrieve matching records
assessmentGR.query();
// Loop through each retrieved record and delete it
while (assessmentGR.next()) {
assessmentGR.deleteRecord(); // Use deleteRecord() for clarity
}
If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik