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.

Gettting data from custom table into catalog item

V_31
Tera Expert

Hi All,

I have a custom table (u_ot_services_and_solutions) which has a field (Site)which references the location table and also a dot.walked field (u_site.site_type) which is also on location table. the "station type" get prepopulated when station is populated.

I then have some other fields on the custom_table which are called "field A, field b, field c.

I now have to bring this information into catalog item if a site is selected from the u_ot_services_and_solutions table, e.g. if a "Site" is selected from catalog item, the 4 customs field also created in catalog item should pre-populate with the information from the dot walked field and fields a to c in their respected fields on catalog item form.

I have tried to create the below but does not seem to work.

Client Script created

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

    var site = g_form.getValue('site');

    //Call script include
    var ga = new GlideAjax('global.siteDetails'); //Scriptinclude
    ga.addParam('sysparm_name', 'getsiteDetails'); //Method
    ga.addParam('sys_id', site); //Parameters
    ga.getXMLAnswer(getResponse);

    function getResponse(response) {
       
        var res = JSON.parse(response);
      
        g_form.setValue('site_type', res.u_site_type);
        g_form.setValue('end_point_device', res.u_endpoint_device);
        g_form.setValue('comms_requirement', res.u_endpoint_device);
    }
    }

 

Script Include

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

    getUserDetails: function(){
        
        var siteDetails = this.getParameter('siteDetails');

        obj = {};

    var grSysSite = new GlideRecord('u_ot_services_and_solutions');
    if (grSysSite.get(details)) {
        obj.site_type =  grSysSite.getValue('u_site_type');
        obj.comms_requirement =  grSysSite.getValue('u_comms_requiremen');
        obj.end_point_device =  grSysSite.getValue('u_comms_requiremen');
    }
    gs.addInfoMessage(obj+JSON.stringify(obj));
    return JSON.stringify(obj);
    },

    type: 'siteDetails'
});

 

2 REPLIES 2

Allen Andreas
Tera Patron

Hello,

Please use the "Insert/Edit code sample" button when pasting code so that it remains organized and easier to ready. The button looks like: { ; }

Please provide more information as to what you mean when you say it doesn't work. That doesn't tell us much nor any troubleshooting you've done to try and assess things on your end?

Within your script include, I see no function called: getsiteDetails

In your Client Script, you're calling GlideAjax and this specific script include, but then also mentioning a function, which doesn't seem to exist, at least from what I can see.

Please review all of your code and check for any issues along these lines.

Here's a GlideAjax cheat sheet just to use as an example, if you need further help: https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

Thanks for marking my reply as Helpful.

If it also helped guide you Correctly, please also mark it as Correct.

Thanks and take care! 🙂


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!