Hide delete button based on a condition in a scoped application

Srikanth Kammil
ServiceNow Employee
ServiceNow Employee

I want to be able to hide the delete button on a form in a scoped app based on a condition. In this case, there is a field called 'state' on the form and if the state is "in_progress", I want to hide the delete button on the form. In order to implement the above, I cloned the existing global delete UI action with same name "sysverb_delete" to override the OOB delete button and added an additional condition. With this, the hide and show of the delete button works as expected.

However, I click the delete button, I see a console error and I do not see the delete confirmation dialog. 

find_real_file.png

The root cause of the error seems to be that there is a script include called, "DeleteRecordAjax" which is called in the client script of the UI action and this is only accessible from the global scope. Since in this case, my UI action is in the application scope, it is not able to access this script include.


function confirmAndDeleteFromForm() {
    objSysId = g_form.getUniqueValue();
    tblName = g_form.getTableName();
    fromRelList = g_form.getParameter('sysparm_from_related_list');
    module = g_form.getParameter('sysparm_userpref_module');
    listQuery = g_form.getParameter('sysparm_record_list');
    stackName = g_form.getParameter('sysparm_nameofstack');
	gotoUrl = g_form.getParameter('sysparm_goto_url');

    ajaxHelper = new GlideAjax('DeleteRecordAjax');
    ajaxHelper.addParam('sysparm_name', 'getCascadeDeleteTables');
    ajaxHelper.addParam('sysparm_obj_id', objSysId);
    ajaxHelper.addParam('sysparm_table_name', tblName);
    ajaxHelper.addParam('sysparm_nameofstack', stackName);
    ajaxHelper.setWantSessionMessages(false);
	if (gotoUrl && gotoUrl != "")
		ajaxHelper.addParam('sysparm_goto_url', setRedirectFields(gotoUrl));

    ajaxHelper.getXMLAnswer(getCascadeDelTablesDoneForm.bind(this), null, null);
}

 

Is there is a way I can make this use case work with UI actions?

 

Note: We have an existing implementation with the client scripts where we currently enable or disable the delete button. The issue with using the client scripts is that on the form load(delete button is disabled case), there is small duration where the button is shown enabled and then it becomes disabled.

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Instead of messing with the ui actions, I would consider adding or modifying the delete ACLs on this table so that the records are deleteable at all in the in_progress state. That would protect you from the list delete ACL as well.

View solution in original post

4 REPLIES 4

maxwell_kruse
Giga Contributor

Have you looked into Cross-scope privilege? You should be able to target the script include in the global scope.

https://docs.servicenow.com/bundle/madrid-application-development/page/build/applications/reference/...

amaradiswamy
Kilo Sage

Hi,

You may try with below.

 

Create a clone of script include in your own application scope and call this script include from UI action.

Update "Accessible from" in script include to "All applications". However, as this is an edit to existing script include it may skip if there are any updates pushed to this script include in next release version of platform.

Check if there is any Restricted Access privileges you can create to allow execution of script include in the application scope​
 

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Instead of messing with the ui actions, I would consider adding or modifying the delete ACLs on this table so that the records are deleteable at all in the in_progress state. That would protect you from the list delete ACL as well.

Thanks Brad. The delete ACL's address our use case!!