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

Amit Verma
Kilo Patron
Kilo Patron

Hi @Ramsha Shaikh 

 

Can you try below logic in your client script to set the field value :

 

var answer= response.responseXML.documentElement.getAttribute("answer");
if(answer){

var final_value = answer.split(",");

var length = final_value.length;

for (var i = 0; i < length; i++)
{
g_form.addOption('servicenow_groups', final_value[i]);
}
}

Thanks & Regards
Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi @Ramsha Shaikh 

 

Can you please accept the solution if it solved your issue ?

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

gkishen84
Tera Contributor

Hi Ramsha,

Why to run the client script instead, why not the variable be a reference field and with a filter query condition?