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

Script include protection read only

ravi2k
Kilo Contributor

Hi Frds,

I`m facing a issue in script include, created script inculde and set protection policy as read only on Fuji version. I have admin rights but not able to edit this? I want to edit or delete this script include. Pls help.

Thanks,

Ravish

1 ACCEPTED SOLUTION

var gr = new GlideRecord("sys_metadata");  


gr.get("42ec6aa0ef62210066fc36caa5c0fbce");   // sys_id of record


gs.print(gr.sys_policy);  


gr.sys_policy="";  


gs.print(gr.sys_policy);  


gr.update();  


View solution in original post

15 REPLIES 15

Subhendu1
Tera Expert
100% working
var
gr = new GlideRecord('sys_script_include'); // Change table if it's a different file type
if (gr.get('96f856f91b0b07105f1c64e1604bcb3c')) {
    // Clear the protection policy that blocks deletion
    gr.setWorkflow(false); // Disable business rules/audit for this cleanup
    gr.AutoSysFields(false);
    gr.sys_policy = '';
    gr.update();
   
    // Now delete the record
    if (gr.deleteRecord()) {
        gs.info('Successfully deleted the protected record.');
    } else {
        gs.error('Failed to delete the record.');
    }
} else {
    gs.print('Record not found.');
}