How to get Cost center in the catalog form

Samiksha2
Mega Sage

Hi,

 

I have a requirement to show the cost center in the catalog form from the custom table.

In the custom table we have only user id.

On change of user id in the form cost center should populate.

Script include:

var requestor_details = Class.create();
requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserDetailsInternal: function() {
        var userName = this.getParameter('sysparm_user');
        var result = "";
        var costing = new GlideRecord("u_custom_user");
        costing.addEncodedQuery('u_useridISNOTEMPTY');
        costing.query();
        if (costing.next()) {
            var cost = costing.u_userid;
            var user = new GlideRecord('sys_user');
            user.addQuery('user_name', cost);
            user.query();
            while (user.next()) {
                result = user.cost_center.getDisplayValue();
            }
        }
        return JSON.stringify(result);
    },
    type: 'requestor_details'
});

Client script:

 var user_id = g_form.getValue('requested');
    var ga = new GlideAjax('requestor_details'); 
    ga.addParam('sysparm_name', 'getUserDetailsInternal'); 
    ga.addParam('sysparm_user', user_id); 
    ga.getXML(EmployeeDetailsLookup); 
}
function EmployeeDetailsLookup(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    var result = JSON.parse(answer);
	alert(result);
    g_form.setValue('cost', result);
}

Please help in this.

 

Thank you!

Samiksha

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

The problem appears to be in your script include. You are doing a search against your custom table but your query is only if u_user_id is not empty. I would think you just need to use the andQuery('u_user_id', userName).

View solution in original post

2 REPLIES 2

Brian Lancaster
Tera Sage

The problem appears to be in your script include. You are doing a search against your custom table but your query is only if u_user_id is not empty. I would think you just need to use the andQuery('u_user_id', userName).

Hi Brian,

 

Yes, you are right. It is working fine.

Thank you.