Assessment Records

Ralton Stewart
Tera Guru

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.

 

1 ACCEPTED SOLUTION

Astik Thombare
Tera Sage

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

 

View solution in original post

1 REPLY 1

Astik Thombare
Tera Sage

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