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.

How to Auto populate Assignment group when we select category and Sub-Category in catalog. I tried

Tulasiram1
Kilo Guru

How to Auto populate Assignment group when we select category and Sub-Category in catalog. I tried with catalog client script and script include but not populating.

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
if(g_form.getValue('sub_category')==''){
return;

}
var Assignment_Group = new GlideAjax('getTitle');
getAssignment_Group.addParam('sysparm_name', 'getAssignment_Group');
getAssigment_Group.addParam('sysparm_user_id', newValue);
getAssignment_Group.getXML(setAssignment_Group);

function setTitle(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue(('job_Assignment_Group', answer));
}


}

 

script include :

var GetAssignment_Group = Class.create();
GetAssignment_Group.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssignment_Group : function(){
var user_id = this.getParameter('sysparm_user_id');
var grUser = new GlideRecord('sys_user');
grUser.addQuery();
if(grUser.next()){
return grUser.getValue('Assignment_Group');
}
},
type: 'GetAssignment_Group'
});

 

 

 

 
 

 

 

7 REPLIES 7

Tulasiram1
Kilo Guru

Tulasiram1_0-1679037703847.png

 

Tulasiram1_1-1679037759719.png

 

 

Mohan raj
Mega Sage

Hi @Tulasiram1 ,

In the both Script having mistakes 

 

To Learn how to write client callble script include with onchange client script reference below link

How to call script include from client script | #s... - ServiceNow Community

 

 

Try this code I hope this helps.

 

Onchange Client Script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    if (g_form.getValue('sub_category') == '') {
        return;

    }
    var Assignment_Group = new GlideAjax('getTitle');
    getAssignment_Group.addParam('sysparm_name', 'getAssignment_Group');
    getAssigment_Group.addParam('sysparm_user_id', g_form.getUniqueValue());
    getAssignment_Group.getXML(setAssignment_Group);

    function setAssignment_Group(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        g_form.setValue('job_Assignment_Group', answer);
    }


}

 

Script include

var getTitle = Class.create();
getTitle.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getAssignment_Group: function () {
        var user_id = this.getParameter('sysparm_user_id');
        var grUser = new GlideRecord('sys_user');
        grUser.addQuery('sys_id', user_id);
        if (grUser.next()) {
            return grUser.getValue('Assignment_Group');
        }
    },
    type: 'getTitle'
});

 

If my response help please mark it correct or helpful.

Regards
Mohan

Hello Mohan not working

 

Tulasiram1
Kilo Guru

Tulasiram1_1-1679040160331.png