What is wrong with my client callable script include

rocio2
Tera Contributor

I have created this script include to push the values of a field into a record producer field when the criteria matches. The debug logs suggest that the query is passing the values. However, I keep getting no values returned and I dont know what is wrong.

This is the script:

var GetFilteredRates = Class.create();
GetFilteredRates.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getFilteredRates: function() {
        var company = this.getParameter('company').trim();
        var passType = this.getParameter('pass_type').trim();

        // Log incoming parameters
        gs.info('Company parameter (trimmed): ' + company);
        gs.info('Pass Type parameter (trimmed): ' + passType);

        if (!company || !passType) {
            gs.info('Error: Missing parameters. Both Company and Pass Type are required.');
            return this.createResponse({ error: "Company and Pass Type are required." });
        }

        var gr = new GlideRecord('sn_hr_core_mgb_mbta_rates');
        gr.addQuery('u_company', company);
        gr.addQuery('u_pass_type', passType);
        gs.info('Encoded Query: ' + gr.getEncodedQuery()); // Log encoded query
        gr.query();

        var rates = [];
        if (gr.hasNext()) {
            while (gr.next()) {
                rates.push({
                    sys_id: gr.getUniqueValue(),
                    name: gr.getDisplayValue('u_pass_name')
                });
            }
            gs.info('Records found: ' + JSON.stringify(rates));
            return this.createResponse({ rates: rates });
        } else {
            gs.info('No records found with the given parameters.');
            return this.createResponse({ error: "No records found for the given criteria." });
        }
    },

    createResponse: function(data) {
        return JSON.stringify(data);
    },

    type: 'GetFilteredRates'
});

The logs are returning the correct values but i am also getting no records found
rocio2_0-1724776737963.png


The table has the records that match the parameters so I should get two results

rocio2_1-1724776873107.png


What am i doing wrong?

6 REPLIES 6

@rocio2 

rocio2_1-1724776873107.pngrocio2_0-1724776737963.png

It looks like there is some extra space between Commuter Zones / Boat (value stored in table) and the same space is absent in your query parameter Commuter Zones/Boat could you please verify this? As if this difference exist then the query would fail and will not return any records.

Do verify what I already mentioned.

 

Reading ServiceNow Support regarding choice values:

"Using special characters in the name, can generate other characters, in the Value field. These characters can cause filtering issues"

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn