Tom Hanson
Tom Hanson

Reputation: 935

SuiteScript 2.0 search filters are throwing an UNEXPECTED _ERROR

I am trying to match a mobile number and/or email number to a customer file. I have created a function to do this for me. When I add the filters to the search I get an UNEXPECTED_ERROR thrown.

function getCustomerByMobilePhoneAndOrEmail(mobile, email)
{
var filterEmail = search.createFilter({
        name : 'email',
        operator : search.Operator.ANYOF,
        values : [ email ]
    });
    /*var filterMobile = search.createFilter({
        name : 'formulanumeric',
        operator : search.Operator.EQUALTO,
        values : ["1"],
        formula : "CASE WHEN {mobilephone} LIKE '"+mobile+"' THEN 1 ELSE 0 END",
    });*/
    var crit = search.create({
        type: search.Type.CUSTOMER,
        filters: [filterEmail]
    });
    log.debug({
        title: "Criteria",
        details: JSON.stringify(crit)
    });
    var results = getAllResults(crit);

    log.debug({
        title: "Results",
        details: JSON.stringify(results)
    });
}

NOTE: I have commented out the mobile for now as I'm trying to jet get the email to work first.

I have checked this against other scripted searches I have performed and I don't see why this one is throwing the error.

Upvotes: 2

Views: 844

Answers (1)

gingin
gingin

Reputation: 151

Upon testing, I got the same unexpected error. Then saw that search operator: ANYOF is not supported for Email Address field type.

Changed the operator to search.Operator.IS and it worked.

Check SuiteAnswers: SuiteScript 1.0 Search Operators (ID: 10565) for the table of supported operators for every field type.

Upvotes: 4

Related Questions