UI 操作在 ServiceNow 工作区中返回未定义的 GlideAjax

问题描述 投票:0回答:1

需求:检查该记录是否有附件。如果是,则允许用户撤销该记录。如果否,则向用户显示错误消息。

在作用域应用程序中运行下面的工作区客户端脚本,单击按钮时出现错误

错误:GlideAjax 中未处理的异常。未定义

工作区客户端脚本

function onClick(g_form) {
    // Check if there are attachments
    checkAttachments(g_form.getUniqueValue(), function(attachmentCount) {
        attachmentCount = parseInt(attachmentCount);
        if (attachmentCount > 0) {
            // If there are attachments, confirm retirement
            var msg = getMessage('When a policy is retired, associated policy acknowledgement campaign is canceled, certain control objectives are also deactivated, and related controls are retired. Are you sure you want to continue?');
            g_modal.confirm(getMessage('Confirmation'), msg).then(
                function onSuccess() {
                     g_form.submit('policy_retire');
                }
            );
        } else {
            // If there are no attachments, show a warning message
            g_form.addErrorMessage("Please add an attachment before retiring the policy.");
        }
    });

    return false;

}

function checkAttachments(sysId, callback) {
    var ga = new GlideAjax('CheckAttachmentsAjax');
    ga.addParam('sysparm_name', 'checkAttachments');
    ga.addParam('sysparm_sysid', sysId);
    ga.getXML(function(response) {
        var attachmentCount = parseInt(response.responseXML.documentElement.getAttribute("answer"));
        callback(attachmentCount);
    });
}

脚本包括

var CheckAttachmentsAjax = Class.create();

CheckAttachmentsAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    checkAttachments: function() {
        var sysId = this.getParameter('sysparm_sysid');
        var attachmentGR = new GlideRecord('sys_attachment');
        attachmentGR.addQuery('table_name', 'sn_compliance_policy');
        attachmentGR.addQuery('table_sys_id', sysId);
        attachmentGR.query();
    
        var attachmentCount = attachmentGR.getRowCount();
        return attachmentCount;
    
    },
    
    type: 'CheckAttachmentsAjax'

});
javascript servicenow serverside-javascript client-side-scripting servicenow-client-scripts
1个回答
0
投票

将脚本包含移动到全局范围修复了它

© www.soinside.com 2019 - 2024. All rights reserved.