Overwriting OOB delete form button (scoped application)

Fredjo
Giga Contributor

Hi Community, 

I have tried to overwrite the default global delete form button without luck. In a scoped application I'm using 'sysverb_delete' on a UI Action to change the button, and that part works fine (see screenshot).

find_real_file.png

In terms of functionality, I have simply just copied the script from the Global Delete UI Action, but whenever I click the button nothing happens. I can't seem to find out what is missing in the script... 

Global Delete script below: 

var ajaxHelper;
var objSysId;
var tblName;
var dlg;
var returnUrl;
var fromRelList;
var module;
var listQuery;
var stackName = null;
var gotoUrl = null;

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);
}

function getCascadeDelTablesDoneForm(answer, s) {
    var ansrArray = answer.split(';');
    returnUrl = ansrArray[0];
    var objList = ansrArray[2];
    var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
    dlg = new dialogClass('delete_confirm_form');
    dlg.setTitle(new GwtMessage().getMessage('Confirmation'));
    if(objList == null) {
       dlg.setWidth(275);
    } else {
       dlg.setWidth(450);
    }
    dlg.setPreference('sysparm_obj_id', objSysId);
    dlg.setPreference('sysparm_table_name', tblName);
    dlg.setPreference('sysparm_delobj_list', objList);
    dlg.setPreference('sysparm_parent_form', this);
    switch (tblName) {
      case 'cmn_notif_device':
        dlg.setPreference('sysparm_msg_override', 'Delete this channel?');
        dlg.setPreference('sysparm_cascade_msg_override', 'Deleting this channel will result in the automatic deletion of the following related records:');
        break;
      case 'cmn_notif_message':
        dlg.setPreference('sysparm_msg_override', 'Delete these conditions?');
        dlg.setPreference('sysparm_cascade_msg_override', 'Deleting these conditions will result in the automatic deletion of the following related records:');
        break;
      case 'sys_notif_subscription':
        dlg.setPreference('sysparm_msg_override', 'Delete this notification?');
        dlg.setPreference('sysparm_cascade_msg_override', 'Deleting this notification will result in the automatic deletion of the following related records:');
        break;
    }
    dlg.render();
}

function deleteCompleted() {
    dlg.destroy();
    var w = getTopWindow();
    cbField = w.document.getElementById('glide_dialog_form_target_' + tblName);
    if(cbField != null) {
        // this is a dialog form, make sure the completion callback is called
        cbField.value = 'sysverb_delete:' + objSysId;
        cbField.onchange();

       // dismiss the dialog form
       var elem = window.parent.document.getElementById('body_FormDialog');
       if (elem)
           new GlideWindow().locate(elem).destroy();
    } else {
        // this is a regular form, use the return URL to back to the correct view, where possible
        if (returnUrl != 'null') {
            window.location.href = returnUrl;
        } else {
            // this is just the default case, in case everything else blows up, should never happen!
            window.location.href = window.location.protocol + '//' + window.location.host + '/' + tblName + '_list.do?sysparm_userpref_module=' + module + '&sysparm_query=' + listQuery + '&sysparm_cancelable=true';
        }
    }
}

// this logic is similar to that in RedirectTransaction.setRedirectURL
function setRedirectFields(gotoURL) {
	if (gotoURL.indexOf('$sys_id') > -1)
		gotoURL = gotoURL.replace(/\$sys_id/g, g_form.getUniqueValue());

	if (gotoURL.indexOf('$action') > -1)
		gotoURL = gotoURL.replace(/\$action/g, 'sysverb_delete');

	if (gotoURL.indexOf('$display_value') > -1)
		gotoURL = gotoURL.replace(/\$display_value/g, g_form.getDisplayValue());

	return gotoURL;
}

Any help would be much appreciated. 

9 REPLIES 9

manish64
Giga Guru

ajaxHelper = new GlideAjax('DeleteRecordAjax'); see scope of this script include 

Fredjo
Giga Contributor

It is in the Global scope, but it should be accessible from all application scopes? 

find_real_file.png

Hi Fredjo,

 

I have not gone through the whole script which you have posted. Just giving a glance to it I would suggest this. Whenever you are calling any global script include, please call it via the API name. Like if the Script Include name is 'testInclude', call it as 'global.testInclude'. It might help you resolving the issue.

 

I hope this helps.Please mark correct/helpful based on impact

Fredjo
Giga Contributor

Hi Amlanpal,

Thanks for the help, but adding global didn't change anything 😕