Using GlideRecord to query values from custom table in Script Include

JohnnieGross
Tera Expert

I have a custom table where I am submitting a query via a script include.   This script include is called from a client script in the Quote object (sn_quote_mgmt_core_quote).  I am working in the native UI as admin and not in the workspace at this point for CSM.   However, when sending the query to the custom table, it always returns null for the value of the field I'm trying to lookup and return in my client script.  This works great if I point it to a non-custom table that we did not create, like customer_account or customer_contact or sys_user etc. where I was hard-coding a Sys ID in the Include Script along with the non-customer table and the return value worked every time.  I tried several custom tables where I also hard-coded the Sys ID, table and return fields and it just doesn't return anything - always null.  I've adjusted the client script to return values from a non-custom table along with the script includes - and it always works as expected with the non-custom table.  

 

I'm wondering if I need to be doing something to my custom table or is it an ACL maybe or something that does not let the GlideRecord query the custom table to return a field value?  That is my guess - but perhaps I'm doing something else wrong.

 

My script include looks like this, referencing the custom table.

 

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

    romAssumptionsDetatils: function() {
        var cr = this.getParameter('sysparm_value');
   
   
       
        var gr = new GlideRecord('u_rom_assumptions');
       

        gr.addQuery('sys_id', cr);
        gr.query();
        if (gr.next()) {
            return gr.u_rom_assumptions_details;
        }

    },

    type: 'getROMAssumptionsInfo'
});
 
JohnnieGross_0-1743600939664.png

 

Thanks for any guidance!

John

 

1 ACCEPTED SOLUTION

JohnnieGross
Tera Expert

I was able to resolve my issue.  Apparently, if the lookup table is made in the Global scope and has the prefix of "u_", then it will not work.  I recreated the table in the application Quote Management Data Model, the system prefixed the table with the prefix for Quote Management and therefore is added to an Application.  Once I did this an updated all my references to that new lookup table and updated the Script Includes, it started working.  I'm not sure why this particular functionality was ignoring a table made in Global, I'm not sure.  But it's working for me now.  Thanks to everyone who helped me navigate this issue.

JohnnieGross_0-1743695215156.png

 

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@JohnnieGross 

are you sure script include is getting called?

your script include is in global scope.

your client script is in which scope?

if it's in other scope then you need to call the script include using the API name i.e. global.getROMAssumptionsInfo

share the client script.

are you using correct GlideAjax call?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you for responding.  Yes, I am referencing the scope that I'm in from the script include - and I added some alerts in the client script so I could see values as they get added - and this all works.  However, it just seems to be on the script include side - where I instead tried things like looking up the email of the client (customer_client) and it returned the value as expected.  Just when I run a query against a custom table in the script include does it seem to ignore the return field.  I checked for typos etc. and it all appears to correct.  Here is my client script:

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

    var romSysID = g_form.getValue('u_quote_rom_assumptions');
   
    alert(romSysID);
    var ga = new GlideAjax('global.getROMAssumptionsInfo');
    ga.addParam('sysparm_name', 'romAssumptionsDetatils');
    ga.addParam('sysparm_value', romSysID);
    ga.getXML(getResult);

    function getResult(response) {
        alert(response);
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
        g_form.setValue('u_quote_rom_assumptions_content', answer);

    }

}

@JohnnieGross 

any query business rule on that custom table which restricts the record in query?

is your client script getting value from script include for admin user?

Is the script include itself getting called?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I do not have any query business rules on the table - and the client script is calling the script include.  If I tweak the script include, for example, to query a different table and return a different value from that table (where the table is not customer and does not begin with "u"), then the client script to the script include works perfectly well.  It's just when I try to query the custom table and cannot see where or how the call from the script include would not be able to run the query and return the value.