CommitNewRow

You can use the CommitNewRow function to commit and save a new DataRow, obtained from GetNewRow, to the specified detail grid or table in the Optiva database. The row can be committed only when all required columns contain valid values. If a row with the same key value already exists, the operation throws an exception to prevent duplication.

When to use

You can use this function to:

  • Add a new DataRow after creating and populating it with GetNewRow.
  • Add new records to Optiva object tabs, such as Ingredients, Parameters, and Labels.

When not to use

You cannot use this function:

  • Before creating and populating a DataRow with GetNewRow.
  • When required column values are missing or invalid.
  • For header or Main tab data.

Syntax

long CommitNewRow(string objSymbol, string objKey, string DetailCode, ref DataRow RowValuesToAdd)

Parameters

Parameter Required Type 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.
DetailCode string Yes

The DTLCODE (Detail Code) corresponding to specific tabs/sections in the Optiva object. For example:

  • INGR - Ingredients
  • TPALL- Parameters
  • BYPROD - Byproducts
RowValuesToAdd DataRow (ref) Yes The DataRow object obtained from GetNewRow, populated with data. The DataRow object passed by reference for modification by the method.

Return Value

The application returns a value zero (0) is returned if the operation is successful.

Impact

The database transactions are committed and cannot be reverted.

Prerequisites

  • All the required columns need valid values.
  • The column data types need to match the schema definition.
  • The key column values need to be unique.

Usage Notes

  • Call GetNewRow() to obtain a blank DataRow.
  • Set values using row["ColumnName"] = value syntax to populate the data.
  • Ensure all required columns have valid values.
  • Call CommitNewRow() to save to database.
  • Validate if the return code is zero (0).

Example

Example 1
Add byproduct with basic fields
//Returns a new datarow
	DataRow newIngrRow = GetNewRow("", "", "BYPROD");
//Set the values in the datarow
   newIngrRow["ITEM_CODE"] = "BYPRODUCT1_AH";
	newIngrRow["QUANTITY"] = 1;
	newIngrRow["UOM_CODE"] = "KG";
	//Add the data in the newly added row
	CommitNewRow("", "", "BYPROD", ref newIngrRow);
Description

Adds a new row with item "BYPRODUCT1_AH" of 1 KG in the Byproducts tab.

Adds a new row with item "BYPRODUCT1_AH" of 1 KG in the Byproducts tab.

Example 1.1
Add byproduct with specification limits
//Returns a new datarow
DataRow drNewRow = GetNewRow("", "", "BYPROD");
			
//Set the values in the datarow
drNewRow["ITEM_CODE"] = "IT1";
drNewRow["QUANTITY"] = "20";
drNewRow["QUANTITY_HI"] = "40";
drNewRow["QUANTITY_LO"] = "10";
			
//Add the data in the newly added row
CommitNewRow("", "", "BYPROD", ref drNewRow);
Description

Adds an item in the Byproducts tab of a specification with Qty%, Qty% Hi, and Qty% Lo values.

Example 2
Add formula to ingredient statement
//Returns a new datarow
DataRow drNewRow = GetNewRow("", "", "LFORM");
//Set the values in the datarow
drNewRow["FORMULA_CODE"] = "FORM1\\001";
//Add the data in the newly added row
CommitNewRow("", "", "LFORM", ref drNewRow);
Description

Adds a formula in the Formula tab of an ingredient statement.

Note: The DTLCODES for the:
  • Formula tab: LFORM
  • Ingredient Statement Rules tab: LRULE
Example 3
Add label to item
//Returns a new datarow
			DataRow newlblrow = GetNewRow("ITEM", "SALT", "LABEL");

			//Set the values in the datarow
			newlblrow["LINE_SORT_ORDER"] = 1;
			newlblrow["LANGUAGE_CODE"] = "EN-US";
			newlblrow["LABEL_TEXT"] = "Salt Label ENUS";

			//Add the data in the newly added row
			CommitNewRow("ITEM", "SALT", "LABEL", ref newlblrow);
Description
Adds a new row with label "Salt Label ENUS" for English language code in the Labels tab of item SALT.
Example 4
Add manual claim to label content
//Returns a new datarow
			DataRow drNewRow = GetNewRow("LABELCONTENT", "LC\001", "MCLAIM");
			
			//Set the values in the datarow
			drNewRow["TYPE_IND"] = "1";
			drNewRow["CLAIM_TEXT_EN-US"] = "Manual Claim statement 1 text entered manually on label content – ENUS.";
			drNewRow["REPORT_IND"] = "0";
			
			//Add the data in the newly added row
			CommitNewRow("", "", "MCLAIM", ref drNewRow);
Description
Adds a new row with claim text for English language code in the Manual Claims tab of label content LC\001.
Example 5
Add extension table data
//Returns a new datarow
			DataRow drNewRow = GetNewRow("", "", "MATRIX.V\\ITEM0");
			
			//Set the values in the datarow
			drNewRow["FIELD2"] = "Brand-X";
			drNewRow["FIELD3"] = "100";
			drNewRow["FIELD4"] = "9/7/2025";
			
			//Add the data in the newly added row
			CommitNewRow("", "", "MATRIX.V\\ITEM0", ref drNewRow);
Description

Adds extension table data in a FORMULA. The detail code format is MATRIX.V\<tableName> (e.g., "MATRIX.V\ITEM0").

Edge Cases

  • The commit fails with an error code, if the required columns are not populated.
  • The operation throws an exception, if a row with the same key already exists.
  • Passing a null DataRow causes an exception or returns an error.
  • An error is returned if incorrect details code is used.
  • If values are set for non-existent columns, an exception occurs.