Ui Action with Script Include

Annette Kitzmil
Tera Guru

Hello,

I have created a UI Action called "Resolve Infraction" that is being used in Workspace.  The UI Action has the condition of: new x_mtbr_ebs_sip_0.EBSSIPUtils().canViewResolveInfraction(), which is just identifying when the user can see the UI Action which is working just fine.  

 

Then I have the client script below that pops up a modal and calls the script include after this to get and passes the sys_id of the record, the comments and state over to the script include.

 

function onClick(g_form) {
    g_modal.showFields({
            title: "Enter any applicable Resolve comments:",
            fields: [{
                type: 'textarea',
                name: 'work_notes',
                label: getMessage('Resolve comments'),              
                mandatory: true
            }],
            size: 'lg'
        }).then(function(fieldValues) {
            //call AJAX script      
            var ga = new GlideAjax('x_mtbr_ebs_sip_0.SIPUtilsAJAX');
            ga.addParam('sysparm_name', 'retailRiskManagerApproval');
            ga.addParam('sysparm_in_progress_state', 'in_progress'); // In Progress
            ga.addParam('sysparm_comments', fieldValues.updatedFields[0].value);
            ga.addParam('sysparm_sysid', g_form.getUniqueValue());
            ga.getXML(reload);
        });
}

function reload() {
    g_form.reload();    
}
 
Here is the script include which is not working at all as it doesn't appear that it is being called upon and I can't figure out what I am missing between the two scripts, can you take a look and let me know if you see anything that may be causing the script include to not work that is being called on here please?
 
var SIPUtilsAJAX = Class.create();
SIPUtilsAJAX.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    /*************************
     ***** Description: Check the status is updating based on the condition met and showing the pop box for comments.
     *****
     ***** Author: AK Date: October 30, 2025
     *****
     ***** Input: sipRecord: x_mtbr_ebs_sip_0_sip_infractions
     *****
     ***** Output: Return: true / false
     *************************/

    sipBankerResolveInfraction: function() {

        var sipSysID = this.getParameter('sysparm_sysid');
        var statusCode = this.getParameter('sysparm_in_progress_state'); // In Progress
        var comments = this.getParameter('sysparm_comments');

        var assignToAnalyst = gs.getProperty('x_mtbr_ebs_sip_0.sip_banker.group');
        var state;

        var grSIP = new GlideRecord('x_mtbr_ebs_sip_0_sip_infractions');
        grSIP.get('sys_id', sipSysID);

        try {

            if (statusCode == 'in_progress') {
                {
                    grSIP.state = '6'; //Resolved
                }
                return;
            }

            if (comments == 'undefined') {
                grSIP.comments = ''; //Clear value
            } else {
                grSIP.comments = comments; //Additional Comments
            }

            grSIP.state = state;
            grSIP.assignment_group = assignToAnalyst;
            grSIP.update();
           
        }catch (error) {
        gs.error('SIP AJAXScript: sipBankerResolveInfraction():' + error);
        gs.addErrorMessage('Please log MyIT ticket for SIP - There was an error with the SIP Banker Resolve');

    }
},

type: 'SIPUtilsAJAX'
});
2 ACCEPTED SOLUTIONS

Annette Kitzmil
Tera Guru

I was able to resolve it by eliminating the AJAX script and just updating the record within the client script:

function onClick(g_form) {
    g_modal.showFields({
        title: 'Add any additional Resolve comments if applicable',
        fields: [{
            type: 'textarea',
            name: 'work_notes',
            label: getMessage('Comments'),
            mandatory: false,
        }],
        size: 'lg'
    }).then(function(fieldValues) {

        if (g_form.getValue('state') == 2) {
            g_form.setValue('state', 6); //Resolved
            g_form.setValue('comments', fieldValues.updatedFields[0].value);
            g_form.save();

        }

        g_form.addInfoMessage("Infraction has been reassigned to the SIP Analyst");

    });

}

View solution in original post

Annette Kitzmil
Tera Guru

Final solution is the following:

 resolveCase: function() {

        var sysId = this.getParameter('sysparm_sysid');
        var canResolve = false;

        var grInfractionTasks = new GlideRecord('x_mtbr_ebs_sip_0_sip_infractions');
        grInfractionTasks.addQuery('state', 'NOT IN', '6,7'); //Resolved or Cancelled
        grInfractionTasks.addQuery('customer_identification_program_ref', sysId);
        grInfractionTasks.query();

        if (grInfractionTasks.getRowCount() == 0) {

            var grSIP = new GlideRecord('x_mtbr_ebs_sip_0_customer_identification_program');
            if (grSIP.get('sys_id', sysId)) {

                grSIP.case_resolved = this.getParameter('sysparm_case_resolved');
                grSIP.resolution_notes = this.getParameter('sysparm_resolution_notes');
                grSIP.state = 6; //Resolved
                grSIP.update();

                canResolve = true;

            }

        }

        return canResolve.toString();

    },
 
Client Script:
function onClick(g_form) {

    var caseResolvedEmpty = g_form.getValue('case_resolved') === '';
    var resolutionNotesEmpty = g_form.getValue('resolution_notes') === '';

    if (caseResolvedEmpty || resolutionNotesEmpty) {
        var missingFields = [];
        g_form.setMandatory('case_resolved', true);
        g_form.setMandatory('resolution_notes', true);

        if (caseResolvedEmpty) {
            g_form.showFieldMsg('case_resolved', 'Required', 'error');
            missingFields.push('Case Resolved?');
        }
        if (resolutionNotesEmpty) {
            g_form.showFieldMsg('resolution_notes', 'Required', 'error');
            missingFields.push('Resolution Notes');
        }
        g_form.addErrorMessage('The following mandatory fields are not filled in: ' + missingFields);
        return false;

    } else {

        var msg = getMessage('are you sure you want to resolve this case?');
        g_modal.confirm('Confirmation', msg, function(confirmed) {
            if (confirmed) {
                var ga = new GlideAjax('x_mtbr_ebs_sip_0.EBSSIPUtilsAJAX');
                ga.addParam('sysparm_name', 'resolveCase');
                ga.addParam('sysparm_sysid', g_form.getUniqueValue());
                ga.addParam('sysparm_case_resolved', g_form.getValue('case_resolved'));
                ga.addParam('sysparm_resolution_notes', g_form.getValue('resolution_notes'));
                ga.getXMLAnswer(checkInfractionStatus);
            }
        });        

    }

    function checkInfractionStatus(answer) {        

        if (answer == 'true') {
            g_form.addInfoMessage('Case has been resolved');
        } else {
            g_form.addInfoMessage('Infraction status must be either Resolved or Cancelled');
        }

    }

}
 

View solution in original post

6 REPLIES 6

Annette Kitzmil
Tera Guru

I was able to resolve it by eliminating the AJAX script and just updating the record within the client script:

function onClick(g_form) {
    g_modal.showFields({
        title: 'Add any additional Resolve comments if applicable',
        fields: [{
            type: 'textarea',
            name: 'work_notes',
            label: getMessage('Comments'),
            mandatory: false,
        }],
        size: 'lg'
    }).then(function(fieldValues) {

        if (g_form.getValue('state') == 2) {
            g_form.setValue('state', 6); //Resolved
            g_form.setValue('comments', fieldValues.updatedFields[0].value);
            g_form.save();

        }

        g_form.addInfoMessage("Infraction has been reassigned to the SIP Analyst");

    });

}

Annette Kitzmil
Tera Guru

Final solution is the following:

 resolveCase: function() {

        var sysId = this.getParameter('sysparm_sysid');
        var canResolve = false;

        var grInfractionTasks = new GlideRecord('x_mtbr_ebs_sip_0_sip_infractions');
        grInfractionTasks.addQuery('state', 'NOT IN', '6,7'); //Resolved or Cancelled
        grInfractionTasks.addQuery('customer_identification_program_ref', sysId);
        grInfractionTasks.query();

        if (grInfractionTasks.getRowCount() == 0) {

            var grSIP = new GlideRecord('x_mtbr_ebs_sip_0_customer_identification_program');
            if (grSIP.get('sys_id', sysId)) {

                grSIP.case_resolved = this.getParameter('sysparm_case_resolved');
                grSIP.resolution_notes = this.getParameter('sysparm_resolution_notes');
                grSIP.state = 6; //Resolved
                grSIP.update();

                canResolve = true;

            }

        }

        return canResolve.toString();

    },
 
Client Script:
function onClick(g_form) {

    var caseResolvedEmpty = g_form.getValue('case_resolved') === '';
    var resolutionNotesEmpty = g_form.getValue('resolution_notes') === '';

    if (caseResolvedEmpty || resolutionNotesEmpty) {
        var missingFields = [];
        g_form.setMandatory('case_resolved', true);
        g_form.setMandatory('resolution_notes', true);

        if (caseResolvedEmpty) {
            g_form.showFieldMsg('case_resolved', 'Required', 'error');
            missingFields.push('Case Resolved?');
        }
        if (resolutionNotesEmpty) {
            g_form.showFieldMsg('resolution_notes', 'Required', 'error');
            missingFields.push('Resolution Notes');
        }
        g_form.addErrorMessage('The following mandatory fields are not filled in: ' + missingFields);
        return false;

    } else {

        var msg = getMessage('are you sure you want to resolve this case?');
        g_modal.confirm('Confirmation', msg, function(confirmed) {
            if (confirmed) {
                var ga = new GlideAjax('x_mtbr_ebs_sip_0.EBSSIPUtilsAJAX');
                ga.addParam('sysparm_name', 'resolveCase');
                ga.addParam('sysparm_sysid', g_form.getUniqueValue());
                ga.addParam('sysparm_case_resolved', g_form.getValue('case_resolved'));
                ga.addParam('sysparm_resolution_notes', g_form.getValue('resolution_notes'));
                ga.getXMLAnswer(checkInfractionStatus);
            }
        });        

    }

    function checkInfractionStatus(answer) {        

        if (answer == 'true') {
            g_form.addInfoMessage('Case has been resolved');
        } else {
            g_form.addInfoMessage('Infraction status must be either Resolved or Cancelled');
        }

    }

}