Filter Product List
  • 13 Mar 2025
  • Dark
    Light

Filter Product List

  • Dark
    Light

Article summary

Purpose

Allows you to run a script to limit the products displayed to a user in CPQ or eCommerce based on custom assortment conditions. For example, you can configure CPQ or eCommerce to display products based on the user's associated account attributes, such as Account Group, Industry, or whether the account is a prospect.

Setup

Upload the script for Filter Product List. For details about uploading and configuring Groovy scripts, read Upload a Groovy script.

Additionally, you can leverage lookup tables to easily manage and maintain assortment-relevant data and streamline the customization process. To leverage lookup tables, use one of the following methods:

  • While uploading your script in CPQ, enter lookup table names in the Lookup Tables field.

  • Query lookup tables in your Groovy script file.

Script

In your script:

  • Import necessary binding variables.

  • Use the ConditionAggregateAND and ConditionAggregateOR classes to define conditions.

  • Use the groovyCtxUtil.isCommerce() class to differentiate between CPQ and eCommerce.

Sample script

import com.imc.context.filters.ConditionAttribute;
import com.imc.context.filters.Condition.OPERATOR;
import com.imc.context.filters.Condition;
import com.google.common.collect.Sets;
import com.imc.vocabulary.Schema;
import com.imc.iss.groovy.salesitem.SalesItemsTree;
import com.imc.iss.groovy.lookupTable.GroovyLookupTable;
import com.imc.util.NullUtil;
import org.apache.commons.lang3.StringUtils;
import com.imc.datamodel.BusinessType;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.jena.ext.com.google.common.collect.Lists;
import com.imc.datamodel.BusinessRelationAttribute;
import com.imc.iss.groovy.orgUnit.OrgUnit;
import com.imc.iss.groovy.GroovyCtxUtil;
import com.imc.iss.groovy.orgUnit.OrgUnitHierarchy;
import com.imc.datamodel.BusinessObject
import com.imc.context.filters.ConditionAggregate
import com.imc.context.filters.ConditionAggregateAND
import com.imc.context.filters.ConditionAggregateOR
 
 
/*
* 
* Groovy implementation of product filtering
*    
*  Binding variables
*  groovyLogger : GroovyLogger
*  groovyCtxUtil : GroovyCtxUtil
*  filterProductScript : Collection<Condition> 
*  userInfo : UserInfo 
*  employee : Employee 
*  contact  : Contact 
*  account  : Account 
*  dbLookupTable : GroovyLookupTable 
*/
 
 
def productCategoryList = [];
def materialGroupList = [];
ConditionAggregateAND conditionAggregateAND1 = new ConditionAggregateAND();
ConditionAggregateAND conditionAggregateAND2 = new ConditionAggregateAND();
ConditionAggregateOR conditionAggregateOR = new ConditionAggregateOR();
 
// Returns true if it's an eCommerce user.
groovyLogger.logDebug("Is this the Commerce User : "+ groovyCtxUtil.isCommerce());
 
// Get the user binding variable.
String username = userInfo.getUsername();
String userURI = userInfo.getUserBO().getUriAsString();
groovyLogger.logDebug("UserInfo user name : "+ username);
 
 
if(groovyCtxUtil.isCommerce() && binding.hasVariable('contact'))
{
    // eCommerce Product filter
    // Get the contact binding variable.
    String contactName = contact.getContactDataAttributeValue("http://www.inmindcloud.com/application/schema.owl#objectName");

    // Get the account binding variable.
    String accountGroup = account.getAccountDataAttributeValue("http://www.inmindcloud.com/application/schema.owl#accountGroup");

    // Query the lookup table.
    def rawData = dbLookupTable.table('PRODUCT_FILTER_URI').addSelectFields('account_group', 'product_category', 'material_group').addCondition('account_group', '==', accountGroup).search();

    rawData.each { line ->
        def productCategory = line['PRODUCT_CATEGORY']
        def materialGroup = line['MATERIAL_GROUP']
        
        if (!NullUtil.isNullorEmpty(productCategory)) {
            productCategoryList.add(productCategory)
        }
        
        if (!NullUtil.isNullorEmpty(materialGroup)) {
            materialGroupList.add(materialGroup)
        }
    }
    
    Condition condition01 = filterFactory.getCondition(Schema.Product, Schema.hasProductClassification, Schema.objectName, "Product", OPERATOR.EQUAL);
    conditionAggregateAND1.and(condition01);
    
    if (productCategoryList.size() > 0)
    {
        Condition condition02 = filterFactory.getCondition(Schema.Product, Schema.linksProductCategory, Schema.objectName, productCategoryList, OPERATOR.EQUAL);
        conditionAggregateAND1.and(condition02);
    }
    
    
    Condition condition03 = filterFactory.getCondition(Schema.objectERPId, "BT" , OPERATOR.EQUAL);
    conditionAggregateAND2.and(condition03);
    if (materialGroupList.size() > 0)
    {
        Condition condition04 = filterFactory.getCondition(Schema.Product, Schema.hasProductMaterialGroup, Schema.objectName, materialGroupList, OPERATOR.EQUAL);
        conditionAggregateAND2.and(condition04);
    }

    // Final condition setup.
    conditionAggregateOR.or(conditionAggregateAND1)
    conditionAggregateOR.or(conditionAggregateAND2)
    
    if (!conditionAggregateAND1.getConditions().isEmpty()){
        filterProductScript.add(conditionAggregateOR);
    }
} else {
    // CPQ Product filter
    // Get the employee binding variable.
    String employeeName = employee.getEmployeeDataAttributeValue("http://www.inmindcloud.com/application/schema.owl#objectName");

    // Query the lookup table.
    def rawData = dbLookupTable.table('PRODUCT_FILTER_URI').addSelectFields('account_group', 'product_category', 'material_group').addCondition('account_group', '==', accountGroup).search();

    rawData.each { line ->
        def productCategory = line['PRODUCT_CATEGORY']
        def materialGroup = line['MATERIAL_GROUP']
        
        if (!NullUtil.isNullorEmpty(productCategory)) {
            productCategoryList.add(productCategory)
        }
        
        if (!NullUtil.isNullorEmpty(materialGroup)) {
            materialGroupList.add(materialGroup)
        }
    }


    if (productCategoryList.size() > 0)
    {
        Condition condition01 = filterFactory.getCondition(Schema.Product, Schema.linksProductCategory, Schema.objectName, productCategoryList, OPERATOR.EQUAL);
        conditionAggregateAND1.and(condition01);
    }
    
    if (materialGroupList.size() > 0)
    {
        Condition condition02 = filterFactory.getCondition(Schema.Product, Schema.hasProductMaterialGroup, Schema.objectName, materialGroupList, OPERATOR.EQUAL);
        conditionAggregateAND1.and(condition02);
    }
    
    if (!conditionAggregateAND1.getConditions().isEmpty()){
        filterProductScript.add(conditionAggregateAND1);
    }
}

Binding variables

In addition to the common binding variables, the following binding variables are available for this extension point.

Variable name

Class

Description

filterProductScript

Collection<Condition>

Adds a collection of aggregate conditions. This variable is returned at the end of the Groovy script.

employee

Employee

Contains the employee information. Use this variable only for CPQ.

contact

Contact

Contains the contact information. Use this variable only for eCommerce.

account

Account

Contains the account information. Use this variable only for eCommerce.

Expected output

No output expected.

Script execution

A script that you upload for this extension point runs automatically when users open a product listing or catalog while performing such actions as placing an order in eCommerce or creating a quote or agreement in CPQ.

If no script is uploaded for this extension point, users see all products in CPQ or eCommerce.


Was this topic helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.