client script is not working on service portal while it is working on console

Prashant Kumar
Tera Contributor

Kindly help me with the below code it is not working on service portal while it is working on ITIL console page

 

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

var buss_ser=g_form.getValue('u_business_services');

var bus_app_name=g_form.getReference('u_business_services').name;
if(buss_ser!=''){
var user_bd='';

var id = g_form.getValue('cmdb_ci');//replace 'u_first_field' with the name of your reference field.
var user = new GlideRecord('cmdb_ci_appl');
user.addQuery('sys_id',id);
user.query();
if ( user.next() ) {
if(user.u_functional_support_group != '')
{
g_form.setValue('assignment_group', user.u_functional_support_group);
}
else
{
if(bus_app_name=='Not Applicable'){
//alert('Not Applicable');
return;
}
user_bd = g_form.getReference('u_requested_for').u_bd___scope;
//alert("user_bd"+user_bd);
if (user_bd == "FCE BD SOUTHWEST MED" || user_bd == "FCE BD SOUTHWEST SP")
{
g_form.setValue('assignment_group',"3c09b8230f5bb54041dd715ce1050ef5");
}
else
{
g_form.setValue('assignment_group',"f2393c230f5bb54041dd715ce1050e62");
}
}

}
}
else{

alert('Please select a Business Service.');
var app_name=g_form.getReference('cmdb_ci').name;
if(app_name!='Not Applicable'){
g_form.setValue('assignment_group',"");
//alert('Not Applicable');
return;
}

g_form.setValue('cmdb_ci',"");
}
//Type appropriate comment here, and begin script below

}

9 REPLIES 9

it is already all 

Prashant Kumar
Tera Contributor

can anyone suggest the script 

@Prashant Kumar  This is how your client script should be updated.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var bus_app_name = '';
    var user_bd = '';
    var app_name = '';
    g_form.getReference('u_requested_for', getUserBD);

    function getUserBD(user) {
        user_bd = user.u_bd___scope;
        g_form.getReference('u_business_services', getBusinessService);
    }

    function getBusinessService(businessService) {
        var buss_ser = g_form.getValue('u_business_services');
        var bus_app_name = businessService.name;
        if (buss_ser != '') {
            var glideAjax = new GlideAjax('MyClient');
            glideAjax.addParam('sysparm_name', 'getAssignmentGroup');
            glideAjax.addParam('sysparam_cmdb_ci_sys_id', g_form.getValue('cmdb_ci'));
            glideAjax.addParam('sysparam_bus_app_name', bus_app_name);
            glideAjax.addParam('sysparam_user_bd', user_bd);
            glideAjax.getXML(getAssignmentGroup);

        } else {

            g_form.getReference('cmdb_ci', getCMDBCI);

        }
    }

    //Type appropriate comment here, and begin script below
    function getAssignmentGroup(response) {
        var assignment_group = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('assignment_group', assignment_group);
    }

    function getCMDBCI(cmdb) {
        app_name = cmdb.name;
        if (app_name != 'Not Applicable') {
            g_form.setValue('assignment_group', "");
            return;
        }
        g_form.setValue('cmdb_ci', "");
    }
}

This is how your Script include should be configured.

Screenshot 2023-04-25 at 1.00.03 PM.png

 

This is the script for your script include.

var MyClient = Class.create();
MyClient.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getAssignmentGroup: function() {
		var id = this.getParameter('sysparam_cmdb_ci_sys_id');
		var bus_app_name = this.getParameter('sysparam_bus_app_name');
		var user_bd = this.getParameter('sysparam_user_bd');      
        var user = new GlideRecord('cmdb_ci_appl');
		var assignment_group = '';
        user.addQuery('sys_id', id);
        user.query();
        if (user.next()) {
            if (user.u_functional_support_group != '') {
                assignment_group =  user.u_functional_support_group+'';
            } else {
                if (bus_app_name == 'Not Applicable') {                    
                    assignment_group = '';
                }                                
                if (user_bd == "FCE BD SOUTHWEST MED" || user_bd == "FCE BD SOUTHWEST SP") {
                    assignment_group =  "3c09b8230f5bb54041dd715ce1050ef5";
                } else {
                    assignment_group = "f2393c230f5bb54041dd715ce1050e62";
                }
            }

        }

		return assignment_group;
    },
    

    type: 'MyClient'
});

Hi Sandeep,

 It is working for backend but not service portal 

@Prashant Kumar  On your Client script, make sure that the UI Type is set to 'All'.

 

Screenshot 2023-05-11 at 1.00.32 PM.png