I have this RESTLET set up. When I run a GET, the ...
# suitescript
n
I have this RESTLET set up. When I run a GET, the search doesn't return anything even though it should.
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType Restlet
 * @NModuleScope SameAccount
 */
define(['N/search', 'N/record'],
    /**
     * @param {search} search
     * @param {record} record
     */
    function (search, record) {

        /**
         * Function called upon sending a GET request to the RESTlet.
         *
         * @param {Object} requestParams - Parameters from HTTP request URL; parameters will be passed into function as an Object (for all supported content types)
         * @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
         * @since 2015.1
         */
        function doGet(requestParams) {
            log.debug({ 'title': 'requestParams', 'details': requestParams });
            var petname = '';

            var contactSearchObj = search.create({
                type: "contact",
                filters:
                    [
                        ["internalid", "anyof", requestParams.id]
                    ],
                columns:
                    [
                        search.createColumn({
                            name: "entityid",
                            sort: search.Sort.ASC,
                            label: "Name"
                        }),
                        search.createColumn({ name: "custentity_kes_test_pt_restlet", label: "KES Test PT Restlet" })
                    ]
            });
            contactSearchObj.run().each(function (result) {
                // .run().each has a limit of 4,000 results
                petname = result.getValue({ 'fieldId': 'custentity_kes_test_pt_restlet' }) ? result.getValue({ 'fieldId': 'custentity_kes_test_pt_restlet' }) : result.getText({ 'fieldId': 'custentity_kes_test_pt_restlet' })
                return true;
            });
            return JSON.stringify(petname)
        }

        /**
         * Function called upon sending a PUT request to the RESTlet.
         * @param {string | Object} requestBody - The HTTP request body; request body will be passed into function as a string when request Content-Type is 'text/plain'
         * or parsed into an Object when request Content-Type is 'application/json' (in which case the body must be a valid JSON)
         * @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
         * @since 2015.2
         */
        function doPut(requestBody) {

        }

        /**
         * Function called upon sending a POST request to the RESTlet.
         *
         * @param {string | Object} requestBody - The HTTP request body; request body will be passed into function as a string when request Content-Type is 'text/plain'
         * or parsed into an Object when request Content-Type is 'application/json' (in which case the body must be a valid JSON)
         * @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
         * @since 2015.2
         */
        function doPost(requestBody) {

            try {

                record.submitFields({
                    'type': 'contact',
                    'id': requestBody.id,
                    'values': {
                        'custentity_kes_test_pt_restlet': requestBody.petname
                    },
                    'options': {
                        'ignoreMandatoryFields': true
                    }
                });

                var contactRec = record.load({ 'type': 'contact', 'id': requestBody.id, 'isDynamic': true });
                log.debug({ 'title': 'PT NAME', 'details': contactRec.getValue({ 'fieldId': 'custentity_kes_test_pt_restlet' }) });

            } catch (ex) {
                log.error({ 'title': 'doPost', 'details': ex.message });
            }
        }

        /**
         * Function called upon sending a DELETE request to the RESTlet.
         *
         * @param {Object} requestParams - Parameters from HTTP request URL; parameters will be passed into function as an Object (for all supported content types)
         * @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
         * @since 2015.2
         */
        function doDelete(requestParams) {

        }

        return {
            'get': doGet,
            'put': doPut,
            'post': doPost,
            'delete': doDelete
        };

    });
s
Assuming your requestParams look as they are expected, log something about the search. Is it actually running but finding no results? Check the count on it, etc.
n
I checked the count and logged values and it returns 0 for the count and an empty string for the log.
But if I do record.load and try and get the value, it prints the value @Sandii