CreateObjectUsingCreateRule
You can use the CreateObjectUsingCreateRule function to create a new Optiva object using a predefined create rule and copy method.
When to use
You can use this function when:
- Creating objects programmatically that require structured naming conventions.
- Creating objects with code segments assigned during creation.
- Creating objects that require specific copy method initialization logic.
When not to use
You cannot use this function for ad-hoc object creation that does not follow predefined patterns.
Syntax
long CreateObjectUsingCreateRule(string objSymbol, string createRule, string copyMethod, Hashtable codeSegments, ref string newKey)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| objSymbol | string | Yes |
The symbol of the object.
Note: You can use empty quotation marks ("") for the current workflow symbol.
|
| createRule | string | Yes | The create rule associated with the object must be provided. |
| copyMethod | string | Yes | The copyMethod associated with the create rule value must be provided. |
| codeSegments | Hashtable | Yes | A hashtable containing code segment names (keys) and their values. The code segments are components of the object key defined by the create rule.
Note: The parameters pass an empty hashtable if no code segments are required by the create rule.
|
| newKey | string (ref) | Yes | The parameter passes an empty string and holds the new object name after the function call. This enables the caller to receive the newly generated key after the object copy is created, without needing to return it from the function separately. |
Return Value
The application returns a value zero (0) is if the operation is successful and negative (-ve) if failed.
Prerequisites
- The create rule must exist and properly configured in the system.
- The copy method must exist and be associated with the create rule.
- The code segments must match those defined in the create rule configuration.
- The object key generation must produce a unique key.
Examples
- Example 1
-
Create a Trade Item using create rule - NEW_TRADE_ITEM, copy method - NEW_TRADE_COPY.
string newKey = ""; Hashtable htCodeSegments = new Hashtable(); htCodeSegments.Add("Company Prefix", "000002"); htCodeSegments.Add("GTIN Type", "GTIN-12"); htCodeSegments.Add("GTIN Template", "FOOD"); long createStatus = CreateObjectUsingCreateRule("TRADEITEM", "NEW TRADE ITEM", "NEW TRADE COPY", htCodeSegments, ref newKey);
- Example 2
-
Create an Item using create rule - NEW_ITEM, copy method - NEW_ITEM_COPY.
string newKey = ""; Hashtable htCodeSegments = new Hashtable(); long createStatus = CreateObjectUsingCreateRule("ITEM", "NEW_ITEM", "NEW_ITEM_COPY", htCodeSegments, ref newKey);