I'm trying to setup a filter to return a set of catalog resources where I filter on a subtenant and resourceType and then also an owner or list of owners. I can't seem to get the filtering working correctly on more than one owner though. I've got my code listed below. I'm sure I'm missing something pretty basic but when I have more than one owner I seem to get all resources of any type for either of the users in any of the subtenants. My goal is to return CatalogResources = subtenant and resourceType and (owner1 or owner2 or owner3 or... ownerX).
This is what I put together so far:
var conditions = new Array();
if (subtenant != null && subtenant != undefined) conditions.push(vCACCAFEFilterParam.equal("organization/subTenant/id", vCACCAFEFilterParam.string(subtenant.id)));
if (resourceType != "ALL") conditions.push(vCACCAFEFilterParam.equal("resourceType/name", vCACCAFEFilterParam.string(resourceType)));
if (owners != null && owners != undefined && owners != "") {
var ownerGroupFilter = new Array();
for each (var owner in owners.split(",")) {
ownerGroupFilter.push(vCACCAFEFilterParam.substringOf("owners/ref", vCACCAFEFilterParam.string(owner)));
}
if (ownerGroupFilter.length > 1) {
conditions.push(vCACCAFEFilterParam.or(ownerGroupFilter));
}
else {
conditions.push(ownerGroupFilter[0]);
}
}
const pageSize = 100; // as of writing this code the max number the rest api returns is 100
var query = vCACCAFEOdataQuery.query();
if (conditions.length > 0 ) {
var filter = new Array();
filter[0] = vCACCAFEFilterParam.and(conditions);
query.addFilter(filter);
}
I've cobbled something together that is working but I'm still hoping there is an easier way to do this as I have a feeling with a bunch of user names I will hit some limit to the number of filters I can have stacked up. But maybe this is the only way to do this?
var subtenantCondition = vCACCAFEFilterParam.equal("organization/subTenant/id", vCACCAFEFilterParam.string(subtenant.id));
var resourceTypeCondition = vCACCAFEFilterParam.equal("resourceType/name", vCACCAFEFilterParam.string(resourceType));
var filters = new Array(); // individual filter parameters
var filter = new Array(); // final array passed in as to query
for each (var owner in owners.split(",")) {
var conditions = new Array();
conditions.push(subtenantCondition);
conditions.push(resourceTypeCondition);
conditions.push(vCACCAFEFilterParam.substringOf("owners/ref", vCACCAFEFilterParam.string(owner)));
filters.push(vCACCAFEFilterParam.and(conditions));
}
filter.push(vCACCAFEFilterParam.or(filters));
var query = vCACCAFEOdataQuery.query().addFilter(filter);