4N335
4N335

Reputation: 281

How to put date filters in search.create() through suitescript 2.0?

I have made a userEvent script (afterSubmit function) on Invoice record. In my script i m creating a search in which in m applying 2 filters on startdate and enddate. I actually need to filter out the line that have startdate and enddatein which my invoice's trandate lays. This is the view of the same search as savedsearch

For example if my trandate is 28/5/2020, than results should show only this line as follows: (because my date resides in between that specific line's start date and end date) enter image description here

Kindly help/suggest anything, I m confused because my results comes out as an empty array when I apply the following code:

my code:

    /* search */
      var ssFilters = [];

      // /* START date */
      ssFilters.push(search.createFilter({
        "name": "custrecord25",// start date
        "operator": search.Operator.ONORAFTER,
        "values": invTranDate
      }));
      // /* END date */
      ssFilters.push(search.createFilter({
        "name": "custrecord26",// end date
        "operator": search.Operator.ONORBEFORE,
        "values": invTranDate
      }));

Upvotes: 1

Views: 2450

Answers (1)

Charl
Charl

Reputation: 827

You only need to use one filter and will need to use the WITHIN operator:

ssFilters.push(search.createFilter({
    "name": "custrecord26",
    "operator": search.Operator.WITHIN,
    "values": [startDate, endDate]
  }));

Good luck!

Upvotes: 3

Related Questions