<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question How to get Cost center in the catalog form in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/how-to-get-cost-center-in-the-catalog-form/m-p/2615624#M498558</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a requirement to show the cost center in the catalog form from the custom table.&lt;/P&gt;&lt;P&gt;In the custom table we have only user id.&lt;/P&gt;&lt;P&gt;On change of user id in the form cost center should populate.&lt;/P&gt;&lt;P&gt;Script include:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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'
});&lt;/LI-CODE&gt;&lt;P&gt;Client script:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; 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);
}&lt;/LI-CODE&gt;&lt;P&gt;Please help in this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Samiksha&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jul 2023 14:27:23 GMT</pubDate>
    <dc:creator>Samiksha2</dc:creator>
    <dc:date>2023-07-17T14:27:23Z</dc:date>
    <item>
      <title>How to get Cost center in the catalog form</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-get-cost-center-in-the-catalog-form/m-p/2615624#M498558</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a requirement to show the cost center in the catalog form from the custom table.&lt;/P&gt;&lt;P&gt;In the custom table we have only user id.&lt;/P&gt;&lt;P&gt;On change of user id in the form cost center should populate.&lt;/P&gt;&lt;P&gt;Script include:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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'
});&lt;/LI-CODE&gt;&lt;P&gt;Client script:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; 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);
}&lt;/LI-CODE&gt;&lt;P&gt;Please help in this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Samiksha&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 14:27:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-get-cost-center-in-the-catalog-form/m-p/2615624#M498558</guid>
      <dc:creator>Samiksha2</dc:creator>
      <dc:date>2023-07-17T14:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to get Cost center in the catalog form</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-get-cost-center-in-the-catalog-form/m-p/2615642#M498560</link>
      <description>&lt;P&gt;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).&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 14:38:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-get-cost-center-in-the-catalog-form/m-p/2615642#M498560</guid>
      <dc:creator>brianlan25</dc:creator>
      <dc:date>2023-07-17T14:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get Cost center in the catalog form</title>
      <link>https://www.servicenow.com/community/itsm-forum/how-to-get-cost-center-in-the-catalog-form/m-p/2615652#M498561</link>
      <description>&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, you are right. It is working fine.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 14:45:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/how-to-get-cost-center-in-the-catalog-form/m-p/2615652#M498561</guid>
      <dc:creator>Samiksha2</dc:creator>
      <dc:date>2023-07-17T14:45:02Z</dc:date>
    </item>
  </channel>
</rss>

