WorkFlow Scripts
- Example 1
-
Update the Item quantity, perform calc all for the formula PIZZASAUCE\001.
- Update ‘IT01’ row Qty in "ITEMLINES" grid/data set of formula PIZZASAUCE\001 to ‘20’.
- Add a subformula in the “ITEMLINES” grid/data set.
- Perform calculation and save.
using System; using Formation.Shared.Defs; class ActionScript : FcProcFuncSetEventWF { public long wf_start() { string formulaKey = "PIZZASAUCE\\001"; string symbol = "FORMULA"; string itemCodeToUpdate = "IT01"; double newQuantity = 20; // Desired quantity try { // 1. Check out the formula for editing int checkoutStatus = CheckOut(symbol, formulaKey); if (checkoutStatus == 0) { MessageList($"Failed to check out formula {formulaKey}"); return 0; } // 2. Update the quantity of the item using ObjPropertySet // PropertyName format: "QUANTITY.INGR.A" ("A" refers to validation record format) long updateQtyResult = ObjPropertySet(newQuantity.ToString(), 1L, "QUANTITY.INGR.A", symbol, formulaKey, itemCodeToUpdate, "ITEM_CODE"); if (updateQtyResult <= 0) { MessageList($"Failed to update quantity for item {itemCodeToUpdate} in formula {formulaKey}"); return 0; } MessageList($"Quantity for item {itemCodeToUpdate} updated to {newQuantity}."); // 3. Perform Calc All Save to recalc formula and subformulas int calcResult = CalcAllSave(ref formulaKey); if (calcResult != 0) { MessageList($"Calculation failed for formula {formulaKey}"); return 0; } MessageList("Calculation and save completed successfully."); return 1; } catch (Exception ex) { MessageList("Error occurred: " + ex.Message); return 0; } } }
- Example 2
-
Add byproducts and comment in Notes tab or Data set for formula PIZZASAUCE\002.
- Add new byproduct ‘ITEM01’ in Byproducts data set for formula PIZZASAUCE\002.
- Add ‘Comments from Workflow’ for comment document code in the notes grid or dataset.
using System; using System.Data; using Formation.Shared.Defs; class ActionScript : FcProcFuncSetEventWF { public long wf_start() { string symbol = "FORMULA"; string key = "PIZZASAUCE\\002"; // target formula (escape backslash) try { // 1) Add Byproduct ITEM01 with default UOM = "KG" string byprodItem = "ITEM01"; string defaultUom = "KG"; // DEFAULT UOM per request DataRow newByprod = GetNewRow(symbol, key, "BYPROD"); if (newByprod == null) { MessageList("Failed to obtain BYPROD new row."); return 0; } newByprod["ITEM_CODE"] = byprodItem; newByprod["QUANTITY"] = 1; // change quantity as needed newByprod["UOM_CODE"] = defaultUom; // Commit the new byproduct row CommitNewRow(symbol, key, "BYPROD", ref newByprod); MessageList($"Byproduct '{byprodItem}' added to {symbol} {key} with UOM={defaultUom}."); // 2) Add comment in Notes / Documents (use doc code "NOTE") // Use FUNCTION_CODE or numeric keycol as configured in your FSDOC/Symbol form. // Here we use keycol = 1 (common) — change if your instance requires a different keycol. long rc = ObjPropertySet("Comments from Workflow", 0, "DOCTEXT.DOC", symbol, key, "NOTE", 1); if (rc >= 0) MessageList("Notes entry added (docCode=NOTE)."); else MessageList($"Failed to add Notes entry (rc={rc})."); return 1; } catch (Exception ex) { MessageList("Error in workflow: " + ex.Message); return 0; } } }
- Example 3
-
Custom table or Extension Table data management for the formula PIZZASAUCE\002.
- In the extensions tab, add below data to the custom table DMFORMULA0:
Param1 – FIELD1 data
Param2 – FIELD2 data
Param3 – FIELD3 data
- Create a copy of this formula and name it as PIZZASAUCE\003.
- In the new formula, remove the custom table data.
- Notify users about the custom table data removal.
using System; using System.Data; using Formation.Shared.Defs; class ActionScript : FcProcFuncSetEventWF { public long wf_start() { string objSymbol = "FORMULA"; string originalKey = "PIZZASAUCE\\002"; string newKey = "PIZZASAUCE\\003"; string extTable = "MATRIX.V\\DMFORMULA0"; string customTable = "DMFORMULA0"; try { // 1. Check if original formula exists if (ObjectExists(originalKey, objSymbol) == 0) { MessageList($"Formula {objSymbol} - {originalKey} does not exist. Aborting."); return 0L; } // 2. Add data to the custom table DMFORMULA0 in the Extensions tab DataRow newRow = GetNewRow(objSymbol, originalKey, extTable); if (newRow == null) { MessageList($"Failed to get a new row for extension table {extTable}."); return 0L; } newRow["FIELD1"] = "Param1 - FIELD1 data"; newRow["FIELD2"] = "Param2 - FIELD2 data"; newRow["FIELD3"] = "Param3 - FIELD3 data"; CommitNewRow(objSymbol, originalKey, extTable, ref newRow); MessageList($"Added data to the custom table '{customTable}' for {objSymbol} {originalKey}."); // 3. Create a copy of the formula as PIZZASAUCE\003 long copyResult = ObjectSaveAs(objSymbol, originalKey, ref newKey); if (copyResult <= 0) { MessageList($"Failed to copy {objSymbol} {originalKey} to {newKey}."); return 0L; } MessageList($"Copied {objSymbol} {originalKey} to {newKey}."); // 4. Remove custom table data from the new formula long removeResult = RemoveCustomTable(customTable, objSymbol, newKey); if (removeResult <= 0) { MessageList($"Failed to remove custom table data from {objSymbol} {newKey}."); return 0L; } MessageList($"Removed custom table data from {objSymbol} {newKey}."); // 5. Notify users about custom table data removal long notifyResult = Notify("FSI", "CUSTOM_TABLE_REMOVAL_NOTIFY", 1, 0, newKey); if (notifyResult > 0) { MessageList("Notification sent successfully."); } else { MessageList("Failed to send notification."); } return 1L; } catch (Exception ex) { MessageList("Error occurred: " + ex.Message); return 0L; } } } - In the extensions tab, add below data to the custom table DMFORMULA0: