Magic Software
Lesson 10Hands-on · ~35 min

Item Validity Check

Once a request is in the system you have to validate the items it asks for. This lesson introduces the Flow Data utility, the Magic xpi ODS, and the Call Flow destination — three tools that together let you check stock for any number of line items in a single request.

The Flow Data Utility

The Flow Data utility manipulates variables, ODS entries, and User Parameter data. You can insert, update, clear, reset, or delete the selected item.

ActionUpdate, Clear, Reset, Delete (ODS only), or Insert (ODS only).
TypeFlow, Context, Global, Business Process, ODS Global, ODS Local, or Environment.
DynIf checked, the variable name is itself an expression.
NameThe target variable name. (For ODS deletes, leave blank to clear all.)
Data Type / Encoding / IndexType and encoding metadata; Index is the position inside an ODS array.
Update ExpressionThe value (an expression) to write.
ConditionBoolean expression that decides whether the action runs.

Using the Flow Data Utility

You'll need two new variables — one per scope:

  1. Under the Scan for New Requests flow, double-click Flow Variables and add F.RequestNum — Numeric, size 5.
  2. Under Repositories, double-click Context Variables and add C.All_Items_Exist — Logical.

Set the Check the Contact step's Processing Mode to Parallel, then add a Flow Data step:

  1. Drop Flow Data as a child of Check if the Customer Exists. Name it Get Req number from FileName.
  2. Open its configuration and click Add twice to add two commands:
ActionTypeNameUpdate Expression
UpdateFlowF.RequestNumVal (Mid (Right (Trim (F.RequestFileName), 7), 1, 3), '5')
UpdateContextC.All_Items_Exist'TRUE'log
The expression explained. Trim strips spaces, Right(...,7) grabs the last seven characters (e.g. 003.xml), Mid(...,1,3) returns the digits, and Val turns the string into a number.

Operational Data Storage (ODS)

The ODS is short-term, shared storage — a database table managed by Magic xpi where flow components can park information for other components or other flows to retrieve. Each entry is keyed by a flow sequence ID plus a UserKey and can be Alpha, Numeric, Date, Time, Logical, or BLOB.

ODS LocalSaved per-thread; cleared when that thread completes.
ODS GlobalSaved globally; available to any flow on any Server in the project.

The ODS supports store, retrieve, and save modes. Compared to the data warehouse, the ODS is your short-term memory — small amounts of recent data, fast simple queries.

Storing the Request in a Dynamic ODS

You'll add the request payload to a dynamic ODS entry from inside the Flow Data step you just built:

  1. Open the Get Req number from FileName step's configuration.
  2. Click Add.
  3. Fill in the row:
ActionTypeDynNameData TypeUpdate Expression
InsertODS Globalchecked'Request_' & Trim(Str(F.RequestNum,'5'))BLOBF.RequestXML
Why "dynamic"? Checking the Dynamic box tells Magic xpi to evaluate Name as an expression. So when F.RequestNum is 1, the ODS entry name becomes Request_1.

When you re-run the same request number, Magic xpi auto-increments an index so the entries don't collide. You can confirm this in the Magic Monitor's ODS view; click the BLOB icon to view the stored payload.

The Check Item Flow

A request can have many items. Rather than build a giant single flow, define a small helper flow called Check Item that checks one item and call it once per request line.

  1. Right-click Business Process-1 and choose Add Flow. Rename it to Check Item.
  2. Add three flow variables: F.ItemCode (Alpha 30), F.RequestNum (Numeric 5), F.Quantity (Numeric 9.2).
  3. Drop a Data Mapper step in the flow and name it Report Items Existence.
  4. Source: a Database source named CheckItemProducts table, StockQuantity column, WHERE [Products].ProductCode = '<?F.ItemCode?>'.
  5. Destination: a Variable destination named Update_General_Check_Var bound to C.All_Items_Exist.
  6. Connect StockQuantity to C.All_Items_Exist.
  7. On the destination node's Calculated Value, enter: Src.S1/Record/StockQuantity >= F.Quantity AND C.All_Items_Exist.
Why the AND? If a previous iteration already found that another item was short, you don't want to flip the answer back to true. ANDing with the previous value preserves "any miss = miss".

Calling Check Item for Each Item

A request often has more than one item. Use the Data Mapper's Call Flow destination to invoke Check Item once per item element in the request XML.

  1. On the Scan for New Requests flow, drop a Data Mapper as a child of Get Req number from FileName. Name it Check Items.
  2. Add an XML source named Items_from_Request; XSD course_data\schemas\request.xsd; Source Type Variable; Variable F.RequestXML.
  3. Add a Call Flow destination named CheckEachItem targeting the Check Item flow.
  4. Connect the item compound node in the source to the Check Item compound node in the destination — this is what makes the called flow fire per item.
  5. Inside the item node connect partNum → F.ItemCode and quantity → F.Quantity.
  6. On F.RequestNum in the destination, set Calculated Value to F.RequestNum — this passes the parent flow's request number into the called flow.

Exercise

Practice these.
  1. Update Check Item to handle two extra cases:
    • The part number doesn't exist in the database.
    • The catalog price is higher than the price the customer offered.
  2. Insert the request into the local MSSQL tables — the request header into Requests (set CustomerExists using whether F.CustomerName is blank), and each line into RequestItems with Status = 'TRUE'Log for valid lines and 'FALSE'Log otherwise.
  3. Create an Auto-Start initialization flow that clears the Requests and RequestItems tables.

Summary

You should now be able to:

  • Use the Flow Data utility to update variables and ODS entries.
  • Insert a dynamic name into an ODS BLOB entry.
  • Build a helper flow and call it from the Data Mapper for every occurrence in a multi-occurrence element.