Formula explosion in Workflows
Three detail types retrieve an exploded list of items for a formula in slightly different ways:
-
LINEEXP
shows like-ingredients combined for all levels of formulas, not including constituents -
LINEEXPRM
shows like-ingredients combined for all levels of formulas, including constituents -
LINELIST
shows like-ingredients separately for all levels of formulas including constituents
The
ObjProperty
,
ObjPropertySet
, and
ObjectsXMLForeign
functions do not work with these
detail types. For example:
dim icodes as object = ObjProperty("ITEMCODE.LINEEXP.A","","","*",1)
XML commands within reporting accept these detail types. For example:
Dim sXML as string = ObjectXML("", "", "HEADER;LINEEXPRM")
Example
A pizza formula has two directly nested sub-formulas for dough and
sauce. Raw material
01032
has a constituent formula. Raw materials
02047
and
19335
are used multiple times at various levels.
This table shows the results of exploding a formula.
LINEEXP
Explode to Raw Material Include intermediate Items Combine like items |
LINELIST
Explode to Constituents Include intermediate items Do not combine like items |
LINEEXPRM
Explode to Constituents Include intermediate items Do not combine like items |
---|---|---|
Line 1: Item = 50012
Line 2: Item = 18375 Line 3: Item = PREMIX Line 4: Item = 02047 Line 5: Item = 04518 Line 6: Item = 19335 Line 7: Item = 20081 Line 8: Item = MIX Line 9: Item = RISE Line 10: Item = SHAPE DOUGH |
Line 1: Item = FS-0011 (SF)
Line 2: Item = 50012 Line 3: Item = 18375 Line 4: Item = PREMIX Line 5: Item = 02047 Line 6: Item = 04518 Line 7: Item = 19335 Line 8: Item = 20081 Line 9: Item = MIX Line 10: Item = RISE Line 11: Item = SHAPE DOUGH Line 12: Item = FS-0013 (SF) |
Line 1: Item = 50012
Line 2: Item = 18375 Line 3: Item = PREMIX Line 4: Item = 02047 Line 5: Item = 04518 Line 6: Item = 19335 Line 7: Item = 20081 Line 8: Item = MIX Line 9: Item = RISE Line 10: Item = SHAPE DOUGH |
Line 11: Item = 11547
Line 12: Item = 04053 Line 13: Item = 11287 Line 14: Item = 02044 Line 15: Item = 02027 |
Line 13: Item = 11547
Line 14: Item = 04053 Line 15: Item = 11287 Line 16: Item = 02044 Line 17: Item = 02027 Line 18: Item = 02047 Line 19: Item = 19335 |
Line 11: Item = 11547
Line 12: Item = 04053 Line 13: Item = 11287 Line 14: Item = 02044 Line 15: Item = 02027 |
Line 16: Item = 11215
Line 17: Item = 01028 Line 18: Item = 07057 Line 19: Item = 11260 Line 20: Item = 01032 (RM) |
Line 20: Item = 11215
Line 21: Item = 01028 Line 22: Item = 07057 Line 23: Item = 11260 Line 24: Item = 01032 (RM) Line 25: Item = 01011 Line 26: Item = 01114 Line 27: Item = 02047 |
Line 16: Item = 11215
Line 17: Item = 01028 Line 18: Item = 07057 Line 19: Item = 11260 Line 20: Item = 01011 Line 21: Item = 01114 |
Line 21: Item = BAKE | Line 28: Item = BAKE
Line 29: Item = 02047 |
Line 22: Item = BAKE |
Use this script to get the exploded items’ XML into a report.
Dim addedItems As New Hashtable 'not really needed unless using LINELIST detail
[unaffected script sections deleted]
'Part 3 - define the XML details for the object(s) in question. Use only what is needed.
'======================================
'Create an XML file for the object. Specify details to include.
sXML = ObjectXML("", "", "HEADER;LINEEXP")
'================ 40
'Part 4 - make modifications to the xml
'======================================
'Strip leading and trailing <fsxml> tags before loading XML fragment
sXML = System.Text.RegularExpressions.Regex.Replace(sXML, "(<|</)fsxml.*?>", "")
'explodedFormula = System.Text.RegularExpressions.Regex.Replace(explodedFormula,
"(<|</)fsxml.*?>", "")
'================
'Part 5 - some xml gymnastics to put things together correctly
'======================================
' You can insert all XML(s) into the template without having to code a for/next loop
xfXMLobject = xdTemplate.CreateDocumentFragment()
xfXMLobject.InnerXml = sXML
'Find the XML node to insert the report data into.
xnRoot = xdTemplate.SelectSingleNode("/fsxml/report/object")
'Insert the object data into the template XML file.
xnRoot.AppendChild(xfXMLobject)
'Add other schemas here, such as referenced objects, line items
'-------------------------
Dim explodedFormula As New XMLDocument() 'create a new xml document and load the sXML
string already 'defined. Will be used solely for getting a list of items in lineexp/
linelist/lineexprm detail explodedFormula.LoadXML(sXML)
Dim ExplodedItems As XmlNodeList = explodedFormula.DocumentElement.SelectNodes("//
FSFORMULALINEEXP/ITEM_CODE") 'or LINEEXPRM or LINELIST as appropriate
For Each ExplodedItem As XmlNode In ExplodedItems
If Not addedItems.Contains(ExplodedItem.InnerText) Then 'not needed unless using
LINELIST detail
Dim XnItem As String
XnItem = Workflow.ObjectXML("ITEM", ExplodedItem.InnerText,"HEADER;STATUS")
'Strip leading and trailing <fsxml> tags before loading XML fragment
XnItem = System.Text.RegularExpressions.Regex.Replace(XnItem, "(<|</)fsxml.*?>",
"")
'Allows for inserting all of the XML(s) into the template without having to code a
for/next loop
xfXMLobject.InnerXml = XnItem
'Insert the object data into the template XML file.
xnRoot = xdTemplate.SelectSingleNode("/fsxml/report/object")
xnRoot.AppendChild(xfXMLobject)
addedItems.Add(ExplodedItem.InnerText,ExplodedItem.InnerText) 'not needed unless
using LINELIST
end if 'not needed unless using LINELIST detail
Next ExplodedItem
[unaffected script sections deleted]