RowUpdate

You can use the RowUpdate function to update an existing row in a detail grid or table of an Optiva object through a script.

When to use

You can use this function when modifying existing rows in detail grids, such as ingredients and parameters.

When not to use

You must not use this function when the row does not exist.

Syntax

RowUpdateReturn RowUpdate(string objSymbol, string objKey, string DetailCode, ref DataRow args, int flags = 0)

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

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

  • INGR - Ingredients
  • TPALL- Parameters
  • BYPROD - Byproducts
args DataRow (ref) Yes The args parameter contains the data row to be updated in the table. The data row returned from GetNewRow is passed as a reference. The method can modify the contents of the row or replace the variable itself. The changed values are reflected in the local variable.
flags int Optional
Flags the parameter for controlling update behavior.
Note: By default value is 0.

Return Value

A DataSet object containing the updated data for the requested detail code is returned. It displays the changes made to the detail grid.

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

Row update process:

  • Call ObjectDataSet() to get the detail grid data.
  • Use DataSetTableName() to get the table name.
  • Get the DataTable from the DataSet.
  • Use Select () or iterate through the rows to find the target row.
  • Update column values in the DataRow.
  • Call RowUpdate() to save the changes to the database.
  • Check the return value for success.

Examples

Example 1
Update ingredient quantity in formula
// get the object
DataSet ds = ObjectDataSet(symbol, formulaKey, "INGR");

			// get the ingridents table
            string ingrTableName = DataSetTableName(symbol, formulaKey, "INGR");
            DataTable ingrTable = ds.Tables[ingrTableName];

			// pick the first Row and update the qty
			DataRow[] rows = ingrTable.Select($"ITEM_CODE = "ITEM1"");
            if (rows.Length > 0)
            {
                rows[0]["QUANTITY"] = 2;
                RowUpdate(symbol, formulaKey, "INGR", ref rows[0]);
			}
Description

Updates ITEM1 quantity to 2 kg in the Item lines tab of the formula.

Note: The ObjectDataSet(symbol, formulaKey, "INGR") returns a DataSet containing all the data rows and related tables for the specified tab (INGR = Formula Ingredients) of the given object.