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'
});
1 ACCEPTED SOLUTION

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

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Annette Kitzmil 

since you are in scoped app, ensure the Script Include is Accessible From All application scopes

I faced this issue recently and the workspace client script was able to call the script include Ajax only with above settings.

It's strange but it worked

AnkurBawiskar_0-1762185883498.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks Tera, I do have it set that way, but I appreciate the feedback.

 

@Annette Kitzmil 

please share screenshots of your UI action, script include etc

try to use getXMLAnswer() in your GlideAjax

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Bert_c1
Kilo Patron

Minor observation, the 'state' variable in the script include is undefined. Declared but no value is assigned.