Search code examples
netsuitesuitescript2.0saved-searches

Saved search Netsuite error in Summary Criteria


Im making a saved search ( find fully applied customer payments) with a summary in criteria
enter image description here

In UI it works fine, but in suitescript gives me this error:

ERROR CODE: INVALID_SRCH_SUMMARY_TYP \n DESCRIPTION: An nlobjSearchFilter contains an invalid summary type: formulanumeric: SUM.

I have tried to load the search

var  searchPayment=search.load({
                   id:'customsearch_paymentsCXC'
                });

Or using the SearchExport extension:

search.create({
                    type: "customerpayment",
                    filters:
                    [
                        ["type","anyof","CustPymt"], 
                        "AND", 
                        ["systemnotes.field","anyof","CUSTBODY_REFJOURNALENTRY_IVA"], 
                        "AND", 
                        ["systemnotes.date","within","thisweek"], 
                        "AND", 
                        ["customer.custentity_zona_cliente","anyof",zonaid], 
                        "AND", 
                        ['sum(formulanumeric: CASE WHEN SUM(NVL({appliedtolinkamount},0)) = MAX(NVL({amount},0)) THEN 1 ELSE 0 END)','equalto','1']
                     ],
                     columns:
                     [
                        search.createColumn({name: "tranid", label: "Document Number"}),
                        search.createColumn({name: "custbody_fe_uuid_cfdi_33", label: "UUID CFDI v3.3"}),
                        search.createColumn({name: "custbody_fe_sf_mensaje_respuesta", label: "Mensaje de Respuesta"}),
                        search.createColumn({
                           name: "tranid",
                           join: "appliedToTransaction",
                           label: "Document Number"
                        }),
                        search.createColumn({
                           name: "internalid",
                           join: "appliedToTransaction",
                           label: "Internal ID"
                        })
                    ]
                 });

and I still getting the same error in the filter with summary :

['sum(formulanumeric: CASE WHEN SUM(NVL({appliedtolinkamount},0)) = MAX(NVL({amount},0)) THEN 1 ELSE 0 END)','equalto','1']

what Im missing here?


Solution

  • Try this

    ...
    Filters: [
        ...
        'AND',
        ['formulanumeric: CASE WHEN sum(nvl({appliedtolinkamount},0)) = max(nvl({amount},0)) THEN 1 ELSE 0 END','is','1']
    ],
    ...