Hiya! Working on an m/r script. Using search.creat...
# suitescript
j
Hiya! Working on an m/r script. Using search.create() to find my records. Below is the filters section of the search... this works in the UI (Saved Search) but is not returning anything in the script. Am I formatting incorrectly? If I remove the 'custentity60' filter, it will work. 'Custentity60' is a List field that references a list of Custom Records. [ignore my terrible field names, they were created before my time].
Copy code
filters: [
  ['custentity58', 'onorafter', 'today'],
  'AND',
  ['custentity60', 'anyof', '@NONE@']
],
a
Map Reduce Scripts are specially good failing silently, post your entire search code, your problem may be in another place... those filters looks good.
j
I'm very early in the script and have commented out almost anything except this search and its logging. Trying to get this data so I can then do stuff do it. 😄
Copy code
/**
 *@NApiVersion 2.1
 *@NScriptType MapReduceScript
 */
define(['N/search', 'N/record'], function(search, record) {

    function getInputData() {

        let contactSearch = search.create({
            type: search.Type.CONTACT,
            filters: [
                ['custentity58', 'onorafter', 'today'],
                'AND',
                ['custentity60', 'anyof', '@NONE@']
            ],
            columns: [
                'internalid',
                'custentity58'
            ]
        });

        return contactSearch;

    }

    function map(context) {
        log.debug('context', context);
        
        // let contactResults = JSON.parse(context.value);
        // let contactId = contactResults.values.internalid.value;
        // let expDate = contactResults.values.custentity58;

        // log.debug('contactid', contactId);
        // log.debug('expdate', expDate);

        // context.write({
        //     key: contactId,
        //     value: expDate
        // });

        
    }

    function reduce(context) {
 

    }

    function summarize(summary) {
        
    }

    return {
        getInputData: getInputData,
        map: map,
        reduce: reduce,
        summarize: summarize
    }
});
a
Your log in the Map Stage is not right
j
Why not? It works if I remove the second filter. I get logging in the map stage then.
a
It should be:
Copy code
log.debug('Each Result in Map', context.value);
j
Nope, still nothing.
the search is returning zero results.
but returns multiple in the UI.
a
What is your MR Deployment EXECUTE AS ROLE?
j
Administrator.
a
And you are sure this exactly same search in returning results in the UI
Copy code
let contactSearch = search.create({
            type: search.Type.CONTACT,
            filters: [
                ['custentity58', 'onorafter', 'today'],
                'AND',
                ['custentity60', 'anyof', '@NONE@']
            ],
            columns: [
                'internalid',
                'custentity58'
            ]
        });
Copy code
['custentity60', 'anyof', '@NONE@']
This is ANYOF in the UI and not NONEOF?
e
I know this is simple, but double check that you're not filtering the logs to error or audit or something on the deployment execution logs tab. (Spent more time that I am willing to admit missing that)
🥴 1
🥲 1
j
Logging set to debug. Returning results in a saved search. Export tool confirms I have search.create() formatted correctly for these fields and I've triple-checked the criteria matches. However, loading in the search module to my browser console, I run the search and just get a bland "Unexpected Error." My favorite NS error as I've only ever fixed on accident. lol
Never mind on the unexpected error. Fixed that. I had none in lowercase (was trying many different solutions). Capitalizing it gives me results.
message has been deleted
I have zero idea what I did but I just ran my script again without making ANY changes and it's working???
This has been 2 days of not working to suddenly working? So confused.
a
Even if this is the regular/recommended approach by NetSuite I don’t like it, what I always try to do is to run the search in the getInputData and build an array of objects with my results already formatted and then return that array of objects/results instead of the raw search object.
💯 1
👍 1
j
Do you have success with that method with nested searches? I've moved them into separate functions so that I could use the data to then do subsequent searching of the records I actually want to alter.
Like in this example, I need a list of contacts who have a specific field with a date set to the future. Then I'll use that list of contacts to narrow down the data of a different record type.
a
It would depend on what Im trying to do, but generally speaking I always build the array of objects(results) with the format and property names I want in the getInputData and then return that array, then in my map phase I know exactly which properties to access or use instead of deep diving into the raw results objects which change with different fields/columns types…
🤔 1
👍🏻 1
Untitled.js
@JessicaL Sample Search:
^^ Notice how I declare my columns only once and I know which properties I would have in the map stage later after each result is returned.
👍🏻 1
🙌 1