简体   繁体   中英

How to search cases by CompanyId in Netsuite Suitescript 2.0?

I can able to search the case by company name

var mySearch = search.create({
      type: search.Type.SUPPORT_CASE,
       columns: [{
          name: 'title'
      }, {
          name: 'company'
      }],
      filters: [{
          name: 'company',
          operator: 'is',
          values: 'Test'
      }]
  });
  return mySearch.run({
    ld: mySearch.id
  }).getRange({
      start: 0,
      end: 1000
  });

But I am not able to search case by company id. companyId is 115

Below are not working

i)

filters: [{
          name: 'company',
          operator: 'is',
          values: 115
      }]

ii)

filters: [{
          name: 'companyid',
          operator: 'is',
          values: 115
      }]

According to the Case schema company is a Text filter, meaning you would have to provide it with the precise Name of the company, not the internal ID.

Instead you may want to use the customer.internalid joined filter to provide the internal ID. Also, Internal ID fields are nearly always Select fields, meaning they do not accept the is operator, but instead require the anyof or noneof operator.

You can find the valid operators by field type on the Help page titled Search Operators

First, you can try this :

var supportcaseSearchObj = search.create({
   type: "supportcase",
   filters:
   [
      ["company.internalid","anyof","100"]
   ],
   columns:
   [
      search.createColumn({
         name: "casenumber",
         sort: search.Sort.ASC
      }),
      "title",
      "company",
      "contact",
      "stage",
      "status",
      "profile",
      "startdate",
      "createddate",
      "category",
      "assigned",
      "priority"
   ]
});

Second : how did I get this ? The answer is hint that will make your life easier :

  1. Install the "NetSuite Saved Search Code Export" chrome plugin.
  2. In Netsuite UI, create your saved search (it is always easier that doing it in code).
  3. After saving the search, open it again for edition.
  4. At the top right corner (near list, search menu in the netsuite page), you will see a link "Export as script" : click on it and you will get your code ;)

If you can not install the chrome plugin :

  1. In Netsuite UI, create your saved search (it is always easier that doing it in code).
  2. In your code, load your saved search
  3. Add a log.debug to show the [loadedesearchVar].filters
  4. You can then copy what you will see in the log to use it as your search filters.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM