J.J.
J.J.

Reputation: 1118

How to create SuiteScript 2.0 saved search with multiple types?

Being relatively new to SuiteScript, are you able to search for multiple types when using search.create()? I know that in the UI this type of search can be created, but did not see any examples in the documentation of such searches, and wanted to double-check of the correct syntax for doing so as well.

var tranSearch = search.create({
            type: [
                search.Type.PURCHASE_ORDER,
                search.Type.VENDOR_BILL,
                search.Type.EXPENSE_REPORT
                ],
            filters: [
                search.createFilter({
                    name    : 'lastmodifieddate',
                    operator: search.Operator.AFTER,
                    values  : formattedDate
                })
            ],
            columns : [
                search.createColumn({name: 'tranid'}),
                search.createColumn({name: 'type'}),
                search.createColumn({name: 'status'})
            ]
        });

Upvotes: 1

Views: 3179

Answers (1)

bknights
bknights

Reputation: 15367

You would do a search on transactions and specify the types in a filter:

var tranSearch = search.create({
    type:'transaction',
    filters:[
       search.createFilter({
          name:'type', 
          operator:search.Operator.ANYOF, 
          values:['PurchOrd', 'VendBill', 'ExpRept']}),
       search.createFilter({
                name    : 'lastmodifieddate',
                operator: search.Operator.AFTER,
                values  : formattedDate
            })
    ],
    columns:...
});

Note: A relatively easy way to get the enumerations for transaction types is: -

  • Open a transaction of the type in which you are interested
  • add &xml=T to the url
  • search for the dbstrantype element. Its value is the value to use in a filter

Another way is to create a saved search in the UI. Save it and then load and parse it in the console.

Upvotes: 3

Related Questions