Trying To Filter Only Rows That Meet Two Criteria

拜拜、爱过 提交于 2019-12-02 12:01:09

Filters are using AND operator. Please consider switching the Datasource Query Builder and applying the following query:

"InventoryStatus != :CompleteStatus OR DeliveryStatus != :DeliveredStatus"

Set CompleteStatus variable to Complete Set DeliveredStatus variable to Delivered

Explanation: Filter you want to apply is "NOT(InventoryStatus = Complete AND DeliveryStatus = Delivered)" which is equivalent to "InventoryStatus != Complete OR DeliveryStatus != Delivered".

Vasyl answer my question perfectly, but I wanted to add a few details in case anyone needs to do the same thing and aren't familiar with using the Datasource Query Builder.

All I did was click the Database I was using and then clicked the Datasources section at the top.

I clicked Add Datasource, named it a new name and pasted Vasyl's code into the Query Builder Expression box.

Two new boxes appear below it allowing me to enter the desired statuses that I wanted to filter out.

Lastly I went back to my Table and changed its datasource to my newly created datasource.

Since you are changing your datasource, if you have any extra code on there it may need to be updated to point to the new datasource.

Example: I had some buttons that would filter entries for the various departments.

So this:

widget.datasource.query.clearFilters();
var datasource = app.datasources.SystemOrders;
var statuses = ['Complete'];
     datasource.query.filters.WarehouseStatus._notIn = statuses;
     datasource.load();

had to change to this:

widget.datasource.query.clearFilters();
var datasource = app.datasources.SystemOrders_HideComplete;
var statuses = ['Complete'];
     datasource.query.filters.WarehouseStatus._notIn = statuses;
     datasource.load();

You can use multiple run and then concatenate their results something like following

/**
 * Retrieves records for ActionItems datasource.
 * @param {RecordQuery} query - query object of the datasource;
 * @return {Array<ActionItems>} user's rating as an array.
 */
function getActionItemsForUser_(query) {
  var userRoles = app.getActiveUserRoles();

  query.filters.Owner._contains = Session.getActiveUser().getEmail();
  var ownerRecords = query.run();
  query.clearFilters();
  query.filters.AddedBy._contains = Session.getActiveUser().getEmail();
  var addedByRecords = query.run();
  return addedByRecords.concat(ownerRecords);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!