Good morning everyone, I have a Map/Reduce that ke...
# suitescript
h
Good morning everyone, I have a Map/Reduce that keeps timing out during the getInputData stage due to a large volume search. What would be the best way to handle this? Thanks in advance
b
what does getInputData look like?
h
getInputData returns a large saved search, more than 21k results...
b
does it return the saved search itself, or the results of the saved search
h
@battk it returns the results
b
usually its more favorable to return the search itself
and let netsuite get the results for you
h
makes sense, thanks let me try that
s
or even easier, return a search reference object
However, in my experience NS will still try to run the entire search before your subsequent stages get invoked, so don't be surprised if it still times out.
b
this particular case will be return the search, she makes the search in code and has multiple formulas
h
@battk in the Map stage, looks like it doesn't return all the columns in the saved search (25 columns). I guess it's due to formula numeric columns. Do you happen to know what's an alternative? context.value returned in Map:
Copy code
{
   recordType: null,
   id: "1",
   values: {
      "GROUP(internalid.transaction)": {
         value: "19957759",
         text: "19957759"
      },
      "GROUP(trandate.transaction)": "10/11/2022",
      "GROUP(type.transaction)": {
         value: "SalesOrd",
         text: "Sales Order"
      },
      "GROUP(tranid.transaction)": "3189088",
      "GROUP(entityid)": "KROCIOH5",
      "GROUP(companyname)": "The Kroger Co",
      "MAX(amount.transaction)": "5.00",
      "GROUP(statusref.transaction)": {
         value: "SalesOrd:B",
         text: "Pending Fulfillment"
      },
      "GROUP(custbody_al_delivery_status.transaction)": {
         value: "2",
         text: "Finished"
      },
      "GROUP(custbody_al_bill_status.transaction)": "",
      "GROUP(custbody_al_ready_to_invoice.transaction)": "F",
      "MAX(custbody_al_estimated_cost.transaction)": "100.00",
      "GROUP(custentity_al_billing_meth)": {
         value: "3",
         text: "Email"
      },
      "MAX(formulanumeric)": "1",
      "MIN(formulanumeric)": "0",
      "GROUP(internalid)": {
         value: "359990",
         text: "359990"
      }
   }
}
@battk here are the columns in the saved search
Copy code
columns:
                    [
                        search.createColumn({
                            name: "internalid",
                            join: "transaction",
                            summary: "GROUP",
                            label: "Internal ID"
                        }),
                        search.createColumn({
                            name: "trandate",
                            join: "transaction",
                            summary: "GROUP",
                            label: "Date"
                        }),
                        search.createColumn({
                            name: "type",
                            join: "transaction",
                            summary: "GROUP",
                            label: "Type"
                        }),
                        search.createColumn({
                            name: "tranid",
                            join: "transaction",
                            summary: "GROUP",
                            label: "Document Number"
                        }),
                        search.createColumn({
                            name: "entityid",
                            summary: "GROUP",
                            sort: search.Sort.ASC,
                            label: "Name"
                        }),
                        search.createColumn({
                            name: "companyname",
                            summary: "GROUP",
                            label: "Company Name"
                        }),
                        search.createColumn({
                            name: "amount",
                            join: "transaction",
                            summary: "MAX",
                            label: "Amount"
                        }),
                        search.createColumn({
                            name: "statusref",
                            join: "transaction",
                            summary: "GROUP",
                            label: "Status"
                        }),
                        search.createColumn({
                            name: "custbody_al_delivery_status",
                            join: "transaction",
                            summary: "GROUP",
                            label: "Delivery Status"
                        }),
                        search.createColumn({
                            name: "custbody_al_bill_status",
                            join: "transaction",
                            summary: "GROUP",
                            label: "Bill Settlement Status"
                        }),
                        search.createColumn({
                            name: "custbody_al_ready_to_invoice",
                            join: "transaction",
                            summary: "GROUP",
                            label: "Ready to Invoice"
                        }),
                        search.createColumn({
                            name: "custbody_al_estimated_cost",
                            join: "transaction",
                            summary: "MAX",
                            label: "Estimated Cost"
                        }),
                        search.createColumn({
                            name: "custentity_al_billing_meth",
                            summary: "GROUP",
                            label: "Billing Method"
                        }),


                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {transaction.custbody_al_final_cost} IN (100,150,200,250) AND {transaction.totalamount} NOT IN ('100',150,200,250, 300) THEN 1 ELSE 0 END",
                            label: "1. Should be a TONU?"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MIN",
                            formula: "CASE WHEN {custentity_al_billing_meth} NOT LIKE '%Email%' THEN 0 ELSE CASE WHEN {contact.custentity_al_send_invoice} = 'T' THEN 0 ELSE 1 END END",
                            label: "2. No Email on File"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {custentity_al_billing_meth} LIKE '%3rd Party Upload%' AND {custentity_al_ar_rep} IS NULL THEN 1 ELSE 0 END",
                            label: "3. 3rd Party Upload - No CRS"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {transaction.custbody_count_podpol_xlr8} > 20 THEN 1 ELSE 0 END",
                            label: "4. POD/BOL Doc > 20"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {transaction.amount} = 0 THEN 1 ELSE 0 END",
                            label: "5. $0 Load"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {transaction.custbody_al_invoice_hold} = 'T' THEN 1 ELSE 0 END",
                            label: "6. On Invoice Hold"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {transaction.custbody_al_final_cost} IN (100,150,200,250) AND {transaction.totalamount} NOT IN (100,150,200,250, 300) THEN 0 ELSE CASE WHEN {custentity_no_pod_required} = 'T' THEN 0 ELSE CASE WHEN {transaction.custbody_al_pod} = 'T' THEN 0 ELSE 1 END END END",
                            label: "7. Document Review - No BOL/POD"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {transaction.department} IS NULL THEN 1 ELSE 0 END",
                            label: "8.1 Missing Department?"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {ccdefault} = 'T' THEN 1 ELSE 0 END",
                            label: "8.3 Customer With Default Credit Card Checked"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {transaction.paymentmethod} = 'VISA' OR {transaction.paymentmethod} = 'Discover' OR {transaction.paymentmethod} = 'American Express' OR {transaction.paymentmethod} = 'Master Card'  THEN 1 ELSE 0 END",
                            label: "8.4 Sales Order Flagged as CC Payment"
                        }),
                        search.createColumn({
                            name: "formulanumeric",
                            summary: "MAX",
                            formula: "CASE WHEN {custentity_do_not_invoice} = 'T' THEN 1 ELSE 0 END",
                            label: "6.1 Customer Invoicing on Hold"
                        }),
                        search.createColumn({
                            name: "internalid",
                            summary: "GROUP",
                            label: "Internal ID"
                        })
]
s
you need to give your formulas unique names, like
name: formulanumeric_1
, etc
h
ahh perfect, that resolved the issue, appreciate it @Sandii
s
If you are still having timeout issues, you could try ungrouping/unsummarizing your search and utilizing the map stage to group the appropirate rows together and doing the calculation in the reduce phase.
👍 1
thankyou 1