I have a map reduce script that is going to duplic...
# suitescript
p
I have a map reduce script that is going to duplicate sales orders based on a search. The issue I am having is that the sales order are not being duplicated. In my log I do see the entries for each SO - but where the log is supposed to show me the internal id is blank - which leads me to believe that the internal id is not being shown in the results and the script does not complete. Below is an excerpt from the script. Can I not use context.id to get the id?
Copy code
function getInputData() {
        var searchObj = search.create({
            type: search.Type.SALES_ORDER,
            filters: [
                ["custbody_show_name","anyof","7253"],
                "AND",
                ["custbody131","anyof","72"]
            ],
            columns: [
                search.createColumn({
                    name: "internalid"
                }),
                search.createColumn({name: "custbody_sop"})
            ]
        });

        return searchObj;
    }

    function map(context) {
        
        var salesOrderId = context.id;
        log.debug("Found Sales Order with ID: ", salesOrderId);
        var newSalesOrder = record.copy({
            type: record.Type.SALES_ORDER,
            id: salesOrderId
        });
e
You want
context.key
, not id
e
It’s possible an exception is being thrown in the map and you’re not raising it.
p
@eblackey - I first wanted to see if it was finding the records in the search and when I saw the blank internal ids in the log it made me think this was why it was not working.
e
Map/Reduce scripts don’t automatically throw exceptions from the map stage so sometimes they can be hidden. I would try putting a try/catch block around the record.copy.
p
copy that. thanks
n
if an error occurs you can iterate the map / reduce errors in summarise, you probably just need to do that to see where it went wrong if indeed it did.
r
https://system.netsuite.com/app/help/helpcenter.nl?fid=section_1517507741.html You want to do what they're suggesting for Summarize. I have no idea what they mean by
The snippet logs data only if an error was thrown during a previous invocation of the map function for the same key/value pair currently being processed.
, but sounds bad lol