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.

Getting below error on portal

Sonali01
Tera Contributor

When I open the demand form on draft or submitted state on the service portal I get the below error.
It's happening in Dev and QA.

Sonali01_0-1712867587764.png

Thanks for your  help in advance

9 REPLIES 9

Hello Marshal,
I tried in Chrome and IE but still same error.

Below is the script do you think , you can point out any error .
Created UI policy Show parent field on demand Screen only to SN_Demand Admins and SN_Admin groups

function onCondition() {    
    var groupNames = 'SN_Demand Admins, SN_Admin'; // Get comma-delimited group names
    var isMember = false;
    var requestsCompleted = 0;
   
    var ga = new GlideAjax('CheckGroupMembership');
    ga.addParam('sysparm_name', 'checkGroupMembership');
    ga.addParam('sysparm_groupNames', groupNames); // Pass the comma-delimited group names
    ga.getXMLAnswer(function(response) {
        // Parse the response string into a boolean value
        if (response === 'true') {
            isMember = true;
        }
        requestsCompleted++;
        checkDisplay();
    });

    function checkDisplay() {
        // Check if all GlideAjax calls have completed
        if (requestsCompleted === 1) {
            g_form.setDisplay('parent', isMember);
        } else {
            g_form.setDisplay('parent', false);
        }
    }
}






 

It looks like you're using a script include ("CheckGroupMembership"), and specifying a function within the script include ("checkGroupMembership") - note, consider naming the class/script include differently than the functions within...unless it is a classless script include, which would be your problem if it is (classless script includes are not available client-side).

My guess is that the "checkGroupMembership" function (within that script include/class) that you call from the GlideAjax is then trying to call "getChannelRW" which may not be available to it.

Perhaps "getChannelRW" is in a server-side script include and failing because it is attempting to call it from the client-side script include (GlideAjax)....you'll need to copy and paste that function into the client-side script include or duplicate the script include which contains it, as a client-side script include.

Sure will try that


Thanks

Hello Marshal,
Also, I found out this under system log - errors

Sonali01_0-1712949609377.png

Thanks 

Hello Marshal sorry pretty new to this, can you help me to achieve 
this my requirement Show parent field on demand Screen only to SN_Demand Admins and SN_Admin groups, so i did below steps

Below is my script include 

var CheckGroupMembership = Class.create();
CheckGroupMembership.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkGroupMembership: function() {
        var groupNames = this.getParameter('sysparm_groupNames').split(','); // Get the group names parameter and split into an array
        var userId = gs.getUserID();
        var isMember = false;

        for (var i = 0; i < groupNames.length; i++) {
            var groupName = groupNames[i].trim(); // Trim any whitespace
            var userGroup = new GlideRecord('sys_user_grmember');
            userGroup.addQuery('user', userId);
            userGroup.addQuery('group.name', groupName);
            userGroup.query();

            if (userGroup.hasNext()) {
                isMember = true;
                break; // Exit the loop if user is found in any group
            }
        }
        return isMember;

        // var userGroups = gs.getUser().getRoles();
        // var isMember = userGroups.indexOf(groupName) !== -1; // Check if the user is a member of the specified group
        // return isMember.toString();
    }
});
 
=============================================================
 
here my ui policy 
 
 
function onCondition() {    
    var groupNames = 'SN_Demand Admins, SN_Admin'; // Get comma-delimited group names
    var isMember = false;
    var requestsCompleted = 0;
   
    var ga = new GlideAjax('CheckGroupMembership');
    ga.addParam('sysparm_name', 'checkGroupMembership');
    ga.addParam('sysparm_groupNames', groupNames); // Pass the comma-delimited group names
    ga.getXMLAnswer(function(response) {
        // Parse the response string into a boolean value
        if (response === 'true') {
            isMember = true;
        }
        requestsCompleted++;
        checkDisplay();
    });

    function checkDisplay() {
        // Check if all GlideAjax calls have completed
        if (requestsCompleted === 1) {
            g_form.setDisplay('parent', isMember);
        } else {
            g_form.setDisplay('parent', false);
        }
    }
}