0
votes

I'm pretty new to SuiteScript but I'm working on a script to send an email to all contacts on the Dunning Recipient list of a customer - so a custom record.

I'm receiving the following error - An nlobjSearchFilter contains invalid search criteria: customrecord_3805_dunning_recipient.custrecord_3805_dunning_recipient_cust.

var filters = new Array();
        filters[0] = new nlobjSearchFilter('company', null, 'is', customer);
        filters[1] = new nlobjSearchFilter('email', null, 'isnot', '');
        filters[2] = new nlobjSearchFilter('isinactive', null, 'is', 'F');
        filters[3] = new nlobjSearchFilter('customrecord_3805_dunning_recipient.custrecord_3805_dunning_recipient_cust', null, 'is', customer);

    var columns = new Array();
        columns[0] = new nlobjSearchColumn('company');
        columns[1] = new nlobjSearchColumn('email');
        columns[2] = new nlobjSearchColumn('internalid')

    var searchresults = nlapiSearchRecord('contact', null, filters, columns);

Is there anything I need to note when using custom records as filters? Thanks

3

3 Answers

1
votes

The second parameter is the joined table. The first one is the column.

Fix your last filter.

1
votes

See below extract from SuiteAnswers on the use of the nlobjSearchFilter() constructor.

nlobjSearchFilter(name, join, operator, value1, value2)

Constructor for a search filter object

Parameters

  • name {string} - The internal ID of the search field. For example, if one of your filtering criterion is Quantity Available, you will set the value of name to quantityavailable, which is the search field ID for Quantity Available.

  • join {string} - If you are executing a joined search, the join id used for the search field specified in the name parameter. The join id is the internal ID of the record type the search field appears on.

  • operator {string} - The search operator used for this search field. For more information about possible operator values, see Search Operators.

Note If your search filter uses the contains search operator and your search times out, use the haskeywords operator instead.

  • value1 {string | date | string[] | int} - A filter value -or- A special date field value -or- Array of values for select/multiselect fields -or- An integer value

  • value2 {string | date} - A secondary filter value -or- special date field value for between/within style operators * lastbusinessweek. Values are not case sensitive. For more information about possible date filter values, see Search Date Filters.

Applying these principles, your filter[3] setting sould be:

filters[3] = new nlobjSearchFilter('custrecord_3805_dunning_recipient_cust', 'customrecord_3805_dunning_recipient', 'anyof', customer);

Note the operator 'anyof' - this is required as when working with a 'List/Record' data type, the only valid operators are 'anyof' and 'noneof'. (I am making an assumption that you are using a List/Record field type to select the related customer in the Dunning Recipient custom record.)

Check your other filters for correct operators too. More information on search operators can be found at SuiteAnswers ID 10565

0
votes

As we do normally in filters,

first parameter is - fieldname (id)

If we want to add this filter from another record we need to use it as second parameter.

second parameter is - join_fieldname (join_record_id)