We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

response to be converted into integer type

Vijay Baokar
Kilo Sage

Hi Team,

I am getting response in floating but i need to have data type as integer in postman response. 

How can i change the data type into integer ?

retrieveUsers: function(pageNumber, pageLength) {
        try {
            var users = [];

            // Default pagination values
            pageNumber = parseInt(pageNumber, 10) || 1;
            pageLength = parseInt(pageLength, 10) || 10;

            // if (isNaN(pageNumber) || pageNumber < 1) pageNumber = 1;
            // if (isNaN(pageLength) || pageLength < 1) pageLength = 10;

            var offset = (pageNumber - 1) * pageLength;

            // Count total users with 'hp.com' email.
            var countGR = new GlideAggregate('sys_user');
            countGR.addEncodedQuery('active=true^emailLIKEhp.com');
            countGR.addAggregate('COUNT');
            countGR.query();

            var totalCount = 0;
            if (countGR.next()) {
                totalCount = parseInt(countGR.getAggregate('COUNT'), 10);
            }

            var totalPages = Math.ceil(totalCount / pageLength);
            if (pageNumber > totalPages && totalPages > 0) {
                return this._errorResponse(400, "Invalid page number. Requested pageNumber: " + pageNumber + " exceeds total available pages: " + totalPages);
            }

            // Fetch paginated users
            var gr_user = new GlideRecord('sys_user');
            gr_user.addEncodedQuery('active=true^emailLIKEhp.com');
            gr_user.orderBy('name');
            gr_user.chooseWindow(offset, offset + pageLength);
            gr_user.query();

            while (gr_user.next()) {

                var vamCountryName = this.getCountryName(gr_user.u_country_vam_countries);
                var bcmCountryName = this.getCountryName(gr_user.u_country_bcm_countries);
                var somCountryName = this.getCountryName(gr_user.u_country_som_countries);
                var market = this.getCountryName(gr_user.u_supported_market_for_market_vam_role);

                users.push({
                    user_id: gr_user.getValue('user_name'),
                    user_email_address: gr_user.getValue('email'),
                    employee_id: gr_user.getValue('employee_number'),
                    status: gr_user.getDisplayValue('active') === 'true' ? 'Active' : 'Inactive',
                    created_date: gr_user.getValue('sys_created_on'),
                    created_by: gr_user.getValue('sys_created_by'),
                    updated_by: gr_user.getValue('sys_updated_by'),
                    updated_date: gr_user.getValue('sys_updated_on'),
                    country_vam_countries: vamCountryName,
                    country_bcm_countries: bcmCountryName,
                    country_som_countries: somCountryName,
                    market_markets: market

                });
            }

            var result = {
                pageNumber: pageNumber,
                pageLength: pageLength,
                totalRecords: totalCount,
                totalPages: totalPages,
                "Status Code": 200,
                "Message": users.length > 0 ? "Users retrieved successfully." : "No users with active status and 'hp.com' email domain were found.",
                users: users
            };
 
Postman response i am getting:
 
"result": {
        "pageNumber": 1.0,
        "pageLength": 10,
        "totalRecords": 88.0,
        "totalPages": 9.0,
        "Status Code": 200,
 
it has to be in integer type and should not be like 1.0 or 88.0
8 REPLIES 8

@Vijay Baokar 

in that method of script include which is returning result

var result = {
                pageNumber: parseInt(pageNumber),
                pageLength: parseInt(pageLength),
                totalRecords: parseInt(totalCount),
                totalPages: parseInt(totalPages),
                "Status Code": 200,
                "Message": users.length > 0 ? "Users retrieved successfully." : "No users with active status and 'hp.com' email domain were found.",
                users: users
            };

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

HI @Ankur Bawiskar Still getting the same response in postman:

"result": {
        "pageNumber": 3.0,

@Vijay Baokar You can explicitly format numbers as strings if the serialization process is not respecting integer values. This is a workaround to ensure that the numbers appear as integers in the JSON response:

for an example:

var result = {
pageNumber: pageNumber.toString(),
pageLength: pageLength.toString(),
totalRecords: totalCount.toString(),
totalPages: totalPages.toString(),
"Status Code": 200,
"Message": users.length > 0 ? "Users retrieved successfully." : "No users with active status and 'hp.com' email domain were found.",
users: users
};

@Vijay Baokar 

did you add log and see what came in script include?

what's the issue with not having integer?

inform 3rd party and they will handle at their end

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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