AddContextAttrib

You can use the AddContextAttrib function to assign one or more context attributes to an Optiva object. This function is used to associate objects (for example, formulas, items) with business contexts such as brands, product types, locations, end uses, or end users.

When to use

You can use this function to:

  • Configure object visibility or applicability by business context.
  • Configure selling or manufacturing location restrictions.
  • Categorise objects by brand, product type, end use, or end user.
  • Manage multiple context attributes for an object in a single operation.

When not to use

You cannot use this function if:

  • The attribute type is not a context attribute.
  • The object is already associated with the specified context attribute.
Note: You can use the HasSetCodes function to validate if the object is associated with a context attribute.

Syntax

long AddContextAttrib(string objSymbol, string objkey, string AttribName, params string[] @params)

Parameters

Parameter Type Required Description
objSymbol string Optional

The symbol of the object.

Note: You can use empty quotation marks ("") for the current workflow symbol.
objKey string Optional

The key of the object.

Note: You can use empty quotation marks ("") for the current workflow symbol.
@params [] string Optional The context attributes to which the object is assigned.
Note: The values must be defined in the attribute specific enumerated lists.
AttribName string Optional The type of attribute.

Return Value

The application returns a value greater than or equal to zero (0) if the operation is successful.

Impact

The function triggers the workflow events or business rules associated with changes to context attributes.

Prerequisites

  • The user must have permissions to modify the context attributes for the specified object type.
  • The context attribute codes passed in @params must exist in the associated enumerated lists.
  • The object specified by objSymbol and objKey must exist in the application.

Examples

Example 1
This example assigns selling locations CA, MA, and TN to formula PIZZASAUCE\003.

AddContextAttrib("FORMULA", "PIZZASAUCE\003", "SELLOC", "CA", "MA", "TN");

Example 2
This example assigns end use (C_ENDUSE) with the code ENUSE_CODE to the current object/symbol .

AddContextAttrib("", "", "C_ENDUSE", "ENUSE_CODE");

Example 3
This example verifies if an Optiva object is assigned an end use context value (C_ENDUSE = "FOOD"), and assigns it if missing.
long lUse = HasContextAttrib("", "", "C_ENDUSE", "FOOD"); 
if (lUse == 0){ 
    long lAdduse = AddContextAttrib("", "", "C_ENDUSE", "FOOD"); 
    MessageList("This formula is for enduse: Food."); 
}
Example 4
This example verifies if the current workflow object (or a specified object) belongs to one or more pizza-related set codes and assigns the end use context attribute C_ENDUSE = "PIZZA".
long lSet = HasSetCodes("", "", "MEAT","SAUCE","DOUGH"); 
if (lSet > 0) { 
    AddContextAttrib("", "", "C_ENDUSE", "PIZZA"); 
    MessageList("Assigned C_ENDUSE='PIZZA'."); 
}
Example 5
Copy Method example
You can construct a copy method to add context attributes to the new object. In this example, the selling location is added using the second auto code segment. The brand is added using the third auto code segment.
long rc = AddContextAttrib("", "", "SELLOC", CopyMethod.Context.GetSegData(2)); 
rc = AddContextAttrib("", "", "C_BRAND", CopyMethod.Context.GetSegData(3));