We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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

Mark Roethof
Tera Patron

Hi there,

 

So basically this part returns nothing? Correct?

 

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();
 
Did you try to debug this part separately, for example with hardcoded values?
 
I'm not sure, though I think some of the values are choices with a slash. Try to avoid that, bad practice and can cause query issues. Not sure if that's your issue.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Sandeep Rajput
Tera Patron

@rocio2 Since this table (sn_hr_core_mgb_mbta_rates) belongs in HR Core scope. Could you confirm the following.

1. In which scope your script include exist? Same as the scope of sn_hr_core_mgb_mbta_rates?

2. If they exist in different scope, do your table and script include have set to All Application scopes?

3. Do you have Caller Access set to Caller Restriction on your  sn_hr_core_mgb_mbta_rates

4. Do you have any invalidate Restricted Caller Access records for HR Core scope and your table?

 

Solution to your issue lies in these questions.

@Sandeep Rajput both table and script include were created in the same scope. 
Caller access is not set to caller restriction on the sn_hr_core_mgb_mbta_rates
I do not have any invalidated restricted caller access record for my table/scope. 

See my comment.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn