Hi,
Today I came across a requirement to use Having function In DAX X++ query .
Here is my Requirement ,
Need to find All the Products added into retail Catalogue, if any of the product more than one time then we need to send a message with that Product name.
Below is the query I used to satisfy my requirement.
Today I came across a requirement to use Having function In DAX X++ query .
Here is my Requirement ,
Need to find All the Products added into retail Catalogue, if any of the product more than one time then we need to send a message with that Product name.
Below is the query I used to satisfy my requirement.
CatalogProductCategory catalogProductCategory;
CatalogProduct catalogProduct;
EcoResProduct ecoresProduct;
Query query = new Query();
QueryBuildDataSource productCategoryQuery,CatalogProductQuery,productQuery;
QueryBuildRange catalogProductRange;
Queryrun queryRunUniquness;
productCategoryQuery =
Query.addDataSource(tableNum(CatalogProductCategory));
CatalogProductQuery =
productCategoryQuery.addDataSource(tableNum(CatalogProduct));
CatalogProductQuery.addSelectionField(fieldNum(CatalogProduct,RECID));
CatalogProductQuery.addSelectionField(fieldNum(CatalogProduct,PRODUCT));
CatalogProductQuery.addGroupByField(fieldnum(CatalogProduct,RecId));
CatalogProductQuery.addGroupByField(fieldnum(CatalogProduct,PRODUCT));
CatalogProductQuery.relations(true);
catalogProductRange =
CatalogProductQuery.addRange(fieldNum(CatalogProduct,Catalog));
catalogProductRange.value(queryValue(catalogId));
productQuery =
CatalogProductQuery.addDataSource(tableNum(EcoResProduct));
productQuery.addSelectionField(fieldNum(EcoResProduct,DISPLAYPRODUCTNUMBER));
productQuery.addGroupByField(fieldnum(EcoResProduct,DISPLAYPRODUCTNUMBER));
productQuery.relations(true);
query.addHavingFilter(productCategoryQuery, fieldStr(CatalogProduct,
RecId), AggregateFunction::Count).value('>1');
//query.
queryRunUniquness = new QueryRun(query);
while(queryRunUniquness.next())
{
ret = false;
catalogProduct =
queryRunUniquness.get(tableNum(CatalogProduct));
EcoResProduct =
queryRunUniquness.get(tableNum(EcoResProduct));
this.populateValidationInfo(ETK_RetailValidationType::Product,catalogProduct.RecId,
strFmt("Product
: %1 exists in more than one node",
EcoResProduct.DisplayProductNumber));
//this.parmcatalogInternalOrg(5637144579);
}
Comments
Post a Comment