Client script and script include suddenly not working

Ramsha Shaikh
Tera Contributor

Hi i have this script include that when the drop down is modify or remove all it shows the groups user is part of in a servicenow group field (i.e a list collector) but for some reason the value is not setting in the field anymore and it isn't showing all the groups the requested for is part of this was working perfectly till yesterday but suddenly it stopped working can someone please help me out with this 

this is my script include

var getAssignmentGroupofMember = Class.create();
getAssignmentGroupofMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getAssignmentGroup: function() {
        var getUser = this.getParameter("sysparm_requestedForValue");
        var getType = this.getParameter("sysparm_type_is");
        gs.log('11-12-23 type is ' + getType);
        gs.log("11-12-23 sys_id: " + getUser);
        if (getType == 'remove_all') {
			
			var grm = new GlideRecord('sys_user_grmember');
            grm.addQuery('user', getUser);
            grm.query();
            var grpArray = [];

            while (grm.next()) {
                grpArray.push(grm.getDisplayValue("group"));
                gs.log("member group array 812" + grpArray+'user is'+getUser);

            }
            return grpArray.toString();
            // gs.print(grpArray);
            // gs.print(grpArray[0]);
        } else if (getType == 'modify') {
            var grp1Array = [];
            var grm1 = new GlideRecord('sys_user_grmember');
            grm1.addQuery('user', getUser);
            grm1.query();
            
            while (grm1.next()) {
                grp1Array.push(grm1.getDisplayValue("group"));
                gs.log('groups not in ' + grp1Array+'user is'+getUser);
            }
            //var a = grp1Array.toString();
            return  grp1Array.toString();
        } //else if(getType == 'add') {
            
            // var grm2 = new GlideRecord('sys_user_grmember');
            // grm2.addQuery('user', getUser);
			
            // grm2.query();
            // var grp2Array =[];
            // while (grp2.next()) {
            //     grp2Array.push(grm2.getDisplayValue("group"));
            //     gs.log('groups in' + grp2Array);

            // }
            // return  grp2Array.toString();
        //}
    },
    type: 'getAssignmentGroupofMember'
});

 and this is my client script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var g_form_item = g_form;
    var requestedforValue = g_form_item.getValue('requested_for');

    var type_is = g_form.getValue('request_type');
    if ((type_is == 'modify') || (type_is == 'remove_all')) {
		
        alert('User will be removed from the groups selected in ServiceNow groups after the group manager approval');
    } 
    var ga = new GlideAjax('getAssignmentGroupofMember');
    ga.addParam('sysparm_name', 'getAssignmentGroup');
    ga.addParam('sysparm_requestedForValue', requestedforValue);
    ga.addParam('sysparm_type_is', type_is);
    ga.getXML(setAssignmentGroup);

    function setAssignmentGroup(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer) {
            //var pa=JSON.parse(answer);
            alert(answer);
            //g_form.clearValue('servicenow_groups');
            g_form.setValue('servicenow_groups',answer);
			
			
			
        }
    }
}

can someone please help out as it is urgent.

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi @Ramsha Shaikh 

 

according to your Script Include you are returning display values from table sys_user_grmember:

 

grp1Array.push(grm1.getDisplayValue("group"));

 

But this is wrong, as list collector fields store Sys IDs.

Instead, use something like this:

 

grp1Array.push(grm1.getValue('group'));

 

Use this approach everywhere in your script and adopt the script code accordingly.

 

Maik

View solution in original post

12 REPLIES 12

Hi @Ramsha Shaikh ,

 

In alert are we getting the values?

Also the service now groups field is of what type?

 

Thanks,

Danish

 

Ramsha Shaikh
Tera Contributor

Hi @Danish Bhairag2 

Alert is getting the values and the servicenow field is a lost collector

I mean a list collector

 

Hi @Ramsha Shaikh ,

 

Can u try this & see if it works

 

 

 g_form.setValue('servicenow_groups',answer.join());

 

 

Thanks,

Danish

 

 

 

Hi @Danish Bhairag2 

No it isn't working its not working its saying an Unhandled exception in GlideAjax. when I go to inspect the error