Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI action working in one instance but not the next

BenjaminY
Tera Contributor

Hello,

I have created a UI action "Cancel Request" button that uses a script include. IT is working as it should in Test/Dev instance but once moved to PROD/UAT button is not working as it should. Per screenshots

UI Action
Form button: True
Active: True
Show insert: True
Show update: True
Client: True
List v2 Compatible:True
Onclick: onCancelClick()
Script:

function onCancelClick() {
    // var dialog = new GlideDialogWindow('x_g_dh5_ccht_deny_reason_popup');
    // //var dialog = new GlideModal('deny_reason_popup');
    // dialog.setTitle('Enter Reason for Cancelling request');
    // dialog.setPreference('sys_id' , g_form.getUniqueValue());
    // dialog.setSize(400);
    // dialog.render();
    console.log(" BY:6/5 Cancel button clicked");
    var reason = prompt("Please provide reason for cancelling request : ");
    if (reason === null) {
        return;
    }
    if (reason && reason.trim() !== " ") {
        var ga = new GlideAjax('cchtCancel');
        ga.addParam('sysparm_name', 'cancelTask');
        ga.addParam('sysparm_task_id', g_form.getUniqueValue());
        ga.addParam('sysparm_reason', reason);
        ga.getXMLAnswer(function(response) {
            var result = response.responseXML.documentElement.getAttribute("answer");
            if (result === 'success') {
                g_form.clearMessage();
                g_form.addInfoMessage('Task Cancelled and approvals updated.');
                g_form.reload();
            } else {
                g_form.addErrorMessage('Error :' + result);
            }
        });
    } else {
        g_form.addErrorMessage("Justification for canelling request is required.")
    }
}

Script include:
Name:cchtCancel
API Name: x_g_dh5_ccht.cchtCancel
Accessible from : This app scope
Client Callable:True
Active:True
Script:
var cchtCancel = Class.create();
cchtCancel.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    cancelTask: function() {
        var taskId = this.getParameter('sysparm_task_id');
        var reason = this.getParameter('sysparm_reason');

        if (!taskId || !reason) {
            return 'Invalid input.';
        }

        var task = new GlideRecord('x_g_dh5_ccht_ccht_task');
        if (!task.get(taskId)) {
            return 'Task not found.';
        }
        task.record_status = 'Cancelled';
        task.state = 'Closed Complete';
        task.work_notes = reason;
        task.update();

        var approvals = new GlideRecord('sysapproval_approver');
        approvals.addQuery('document_id', task.sys_id);
        approvals.addQuery('approver', gs.getUserID());
        approvals.addQuery('state', 'requested');
        approvals.query();
        if (approvals.next()) {
            approvals.state = 'cancelled';
            approvals.comments = reason;
            approvals.update();
        }

        var others = new GlideRecord('sysapproval_approver');
        others.addQuery('document_id', task.sysId);
        others.addQuery('sys_id', '!=', approvals.sys_id);
        others.addQuery('state', 'requested');
        others.query();

        while (others.next()) {
            others.state = 'not_required';
            others.comments = 'CCHT Team cancelled request, approval no longer needed.';
            others.update();
        }
        return 'success';
    },

});
PROD/UAT:
BenjaminY_2-1750977927456.png

 


TEST/DEV:

BenjaminY_1-1750977835439.png

 



1 REPLY 1

Kirby R
Kilo Sage

did you get the message from the console in your dev tools?