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.

Unable to see details on fields in service portal

shaik17
Tera Contributor

Hi friends,

i am unable to see user related details in service portal, i am able to see in back end. Attached screen shots for reference. we have one script include (Global) and On change client script in (Hr application), i have added bothe script screen shots as well. Please assist me why this happens.

Service portal:

shaik17_0-1729861270890.png

shaik17_1-1729861317221.png

shaik17_0-1729862384280.png

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

    getUserInfo: function() {
        // Log the incoming parameter
        var userId = this.getParameter('sysparm_userId');
        if (!userId) {
            gs.error('No userId provided');
            return JSON.stringify({ error: 'Invalid or missing userId' });
        }
        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', userId);
        gr.query();

        var jsonObj = {};
        if (gr.next()) {
            // Extract and log the values
            jsonObj.title = gr.getDisplayValue('title');
            jsonObj.manager = gr.getDisplayValue('manager');
            jsonObj.department = gr.getDisplayValue('department');
            jsonObj.location = gr.getDisplayValue('location');

        } else {
            gs.error('User not found with sys_id: ' + userId);
            return JSON.stringify({ error: 'User not found' });
        }

        // Return the user details as JSON
        return JSON.stringify(jsonObj);
    },

    type: 'sampleUtils'
});

 

shaik17_1-1729862459967.png

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var userSysId = g_form.getValue('employee');
   
    if (userSysId) {
        var ga = new GlideAjax('global.sampleUtils ');
        ga.addParam('sysparm_name', 'getUserInfo');
        ga.addParam('sysparm_userId', userSysId);
        ga.getXML(callback);
    }

    function callback(response) {

        var answer = response.responseXML.documentElement.getAttribute("answer");
        var returneddata = JSON.parse(answer);
        g_form.setValue("employee_title", returneddata.title);
        g_form.setValue("employee_department", returneddata.department );
        g_form.setValue("employee_manager", returneddata.manager);
        g_form.setValue("employee_location", returneddata.location);
    }

}



 

0 REPLIES 0