Code to Create a New Expression

This section describes how to create a new expression.

  1. Using the ExpressionStore object, oExpressionStore, created in Code to Connect to the Expression Store, create an empty recordset to contain the new expression.

    Dim rsExpr
    Set rsExpr = oExpressionStore.NewExpression()
    
  2. The returned recordset is an ADO hierarchical Recordset object. It contains one parent and two child Recordset objects, one child for profile dependencies and one child for expression dependencies. Populate the fields in the parent recordset. The string, sXMLExpression, used for the ExprBody field, is defined in Code to Evaluate an Expression Stored as an XML Fragment. No error checking is performed on the syntax of this string when the Recordset object is saved. Use the ParseXML method to verify the correct syntax before saving the recordset. If the expression is meant to appear as a target or catalog expression in the Campaign Expressions module in Commerce Server Business Desk, the Category field must be set to "CAMPAIGNS" or "CATALOG", respectively.

    rsExpr.Fields("ExprName").Value = "Expr_WA_Joe"
    rsExpr.Fields("ExprBody").Value = sXMLExpression
    rsExpr.Fields("Category").Value = "WA Users"
    rsExpr.Fields("ExprDesc").Value = "Is the user from WA and named Joe?"
    
  3. Add and populate a new record in the profile dependencies child recordset for each profile the new expression depends on. At least one profile dependency is required to evaluate the expression against.

    Dim rsDeps
    Set rsDeps = rsExpr.Fields("rsProfDeps").Value
    
    rsDeps.AddNew
    rsDeps.Fields("ProfDep").Value = "User"
    rsDeps.AddNew
    rsDeps.Fields("ProfDep").Value = "Address"
    
  4. Add and populate a new record in the expression dependencies child recordset for each expression the new expression depends on. An expression does not have to depend on other expressions; thus, this step is optional.

    Set rsDeps = rsExpr.Fields("rsExprDeps").Value
    
    rsDeps.AddNew
    rsDeps.Fields("ExprDep").Value = 123
    
  5. Save the expression in the Expression Store and release the Recordset objects.

    oExpressionStore.SaveExpression(rsExpr)
    
    Set rsDeps = Nothing
    Set rsExpr = Nothing
    


All rights reserved.