Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to delete the record in asmt_metric table

mania
Tera Contributor

Hi,

I am not able to delete the record in asmt_metric table.

Do we need to do with any ACL's if yes please let me know.

Can anyone please help on this, It will be gratefull

OOB ACL's:

mania_2-1745930466244.png

Thanks!

3 REPLIES 3

Dr Atul - LNG
Tera Patron

Hi @mania 

 

I tried in my PDI and i am able to delete the record from asmt_metric table without any issue. i have admin role. Please check the delete ACL what role is required .

****************************************************************************************
Regards
Dr Atul G. - Learn N Grow Together ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
******************************************************************************************

Ankur Bawiskar
Tera Patron

@mania 

Please check if somebody updated the ACL for admins.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

LShetler
Tera Contributor

@mania
Were you ever able to figure this out? I just ran into the same thing and discovered there is a canDeleteMetric function being called from the AssessmentUtils Script Includes that controls when a Metric from asmt_metric can be deleted.

For my use case, I had to delete all records from the Metric Results (asmt_metric_result) table that were tied to the Metric that needed to be deleted. Once that was complete, I was able to delete the Metric.



canDeleteMetric: function(metricGR) {
        var metricResultGR = new GlideRecord('asmt_metric_result');
        var canDelete = true;
        if (metricGR != null) {
            if (metricGR.datatype == 'attachment') {
                metricResultGR.addQuery('metric', metricGR.getUniqueValue());
                metricResultGR.query();
                var metricResultSysID = [];
                while (metricResultGR.next()) {
                    metricResultSysID.push(metricResultGR.getUniqueValue());
                }
                var attachmentGR = new GlideRecord('sys_attachment');
                attachmentGR.addQuery('table_name', 'asmt_metric_result');
                attachmentGR.addQuery('table_sys_id', 'IN', metricResultSysID.join());
                attachmentGR.query();
                if (attachmentGR.hasNext())
                    canDelete = false;
            } else {
                var encodedQuery = 'metric.datatypeINdate,datetime,string^string_valueISNOTEMPTY^metric=';
                encodedQuery += metricGR.getUniqueValue();
                encodedQuery += '^NQmetric.datatype=reference^reference_value!=-1^metric=';
                encodedQuery += metricGR.getUniqueValue();
                encodedQuery += '^NQmetric.datatypeINchoice,imagescale,scale,multiplecheckbox,long,numericscale,percentage,ranking,template,boolean^actual_value!=-1^metric=';
                encodedQuery += metricGR.getUniqueValue();
                encodedQuery += '^NQmetric.datatype=checkbox^metric=';
                encodedQuery += metricGR.getUniqueValue();
                metricResultGR.addEncodedQuery(encodedQuery);
                metricResultGR.query();
                if (metricResultGR.hasNext())
                    canDelete = false;
            }
        }
        return canDelete;
    },