The CreatorCon Call for Content is officially open! Get started here.

Scope of GlideRecord.CanDelete();

Matt102
Giga Guru

Hi,

I was wondering about (pointlessly?) doing a belt and braces check before deleting a record. From what little I know of table, row & field ACLs, I believe the best place to do a canDelete() check would be inside my record loop as in:

var gr = GlideRecord('sc_req_item'); 
gr.addQuery('cat_item', sid);
gr.query();
while (gr.next()){
    if (gr.canDelete()) {
        // do delete
    } else {
        // log fail
    }
}
Is that correct or does the canDelete apply to the whole record set returned by the query (such that you would place a check outside the while loop)?
 
Thanks,
Matt
 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Matt,

canDelete() evaluates ACL and it should be table level I believe i.e. record level as you will be deleting record

I believe you can use canWrite() at field level and also canRead(); canCreate(), canDelete() won't work at field level

example: current.state.canWrite()

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_GlideRecordAPI#r_Gli...

https://hi.service-now.com/kb_view.do?sysparm_article=KB0677278

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

3 REPLIES 3

Tanushree Doiph
Mega Guru

Hey,

Instead of sid, write sys_id.

Thanks

Tanushree

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Matt,

You can do the check outside the while loop(At Table level) and then  continue with next steps I.e

var gr = GlideRecord('sc_req_item');

var Del = gr.canDelete();

if(Del == true)

{

//

}

https://docs.servicenow.com/bundle/orlando-application-development/page/app-store/dev_portal/API_ref...

 

- Pradeep Sharma 

- Pradeep Sharma

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Matt,

canDelete() evaluates ACL and it should be table level I believe i.e. record level as you will be deleting record

I believe you can use canWrite() at field level and also canRead(); canCreate(), canDelete() won't work at field level

example: current.state.canWrite()

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_GlideRecordAPI#r_Gli...

https://hi.service-now.com/kb_view.do?sysparm_article=KB0677278

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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