This topic contains 2 replies, has 0 voices, and was last updated by Gopher 7 years, 4 months ago.

  • Author
    Posts
  • #21530

    Gopher

    Hi all! First post here.

    Background:

    I'm creating a HTML customer dashboard portlet to show customized views based on customer type and color-code important information for support representatives. To display all relevant customer information within one portlet, I am using nlapiLoadSearch() to return the results for a couple of custom searches I have defined and am then formatting the results into lists within the HTML.

    Issue:

    In native search portlets, running a custom search for supportcase or contact items only returns ones relevant to that customer to the portlet. This scope limiting seems to be built in, as when I run a nlapiLoadSearch() from my HTML portlet it returns all supportcase or contact items.

    For this reason, I need to filter my search results to only return cases or contacts for the customer which is currently open. Now, the following code seems to work for cases:

    var search = nlapiLoadSearch('supportcase', 'customsearch1492');

    var newFilter = new nlobjSearchFilter('company', null, 'contains', fieldarray['companynametext']);

    search.addFilter(newFilter);

    var resultSet = search.runSearch();

    (NOTE: "fieldarray ['companytypetext']" above stores the value found at nlapiLoadRecord('customer', entityid).getFieldText('custentity1'))

    However, when I try to do the same thing for contacts:

    var search = nlapiLoadSearch('contact', 'customsearch1472');

    var newFilter = new nlobjSearchFilter('company', null, 'contains', fieldarray['companynametext']);

    search.addFilter(newFilter);

    var resultSet = search.runSearch();

    I get the following error: An nlobjSearchFilter contains an invalid operator, or is not in proper syntax: company.

    (NOTE: Of course, both of the "search" variables are in different scopes and so don't clash in case that was a concern. I still get this error even if the supportcase one is commented out!)

    The second custom search works fine without the company filter, and performing getText('company') on any result gives a string which is the correct company. When I open a contact record and view the Field Help tooltip, it also shows "Field ID: company". This is also correct according to the documentation found at https://system.na1.netsuite.com/help…d/contact.html

    It's maybe a little bit janky to use a text filter to make company names match up instead of filtering by entityID of the parent (customer) object, but I can't seem to find any way to reference it from a saved search :<

    What on earth could be going wrong here? Why am I not able to filter by Company for Contact objects while I am able to do so fine for Supportcases, when they both use the same Field ID with the same text?
    This is a cached copy. Click here to see the original post.

  • #21531

    erictgrubaugh

    On a Case record, the Company field is a Text field, so `contains` is a valid operator.

    On a Contact record, the Company field is a Select field (dropdown), so `contains` is not a valid operator. You will need to use `anyof` instead of `contains`.

    See the Help article "Search Operators" for details on which operators can be applied to which field types.


    Gopher replied on 07/11/2017, 02:00 PM: Thanks for the quick response! I have tried using ‘anyof’ instead of ‘contains’ as well, but when I do so it doesn’t seem to filter at all? i.e. if I am on Company N’s page, contacts for Company X show up with that filter.

  • #21532

    Gopher

    I've tried something similar to that, with no luck. I modified the code as follows:

    var search = nlapiLoadSearch('contact', 'customsearch1472');

    var filterterms = [];

    filterterms[0] = "Nova"; //I included the full customer name in the actual code but it is redacted here

    var newFilter = new nlobjSearchFilter('company', null, 'anyof', filterterms);

    search.addFilter(newFilter);

    var resultSet = search.runSearch();

    This returns a contact who works for the company named "Direct".

    The array example you gave me only has numeric values: should I be using the customer's EntityID instead of the company name since it is a Select field?

    EDIT: …Aha! Yes, it appears that EntityID works. So using Contains on a text field requires text, but using AnyOf on a select field requires EntityID instead of the text content which appears in that select field. When I performed

    var search = nlapiLoadSearch('contact', 'customsearch1472');

    var filterterms = [];

    filterterms[0] = "4581"; //test code of course, it'll be a variable later

    var newFilter = new nlobjSearchFilter('company', null, 'anyof', filterterms);

    search.addFilter(newFilter);

    var resultSet = search.runSearch();

    it returned the proper contact!

    Thanks so much!


    erictgrubaugh replied on 07/12/2017, 07:43 AM: Correct; Select fields will always require Internal IDs for their values either when filtering them or setting them.

You must be logged in to reply to this topic.