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.
| Action | Update, Clear, Reset, Delete (ODS only), or Insert (ODS only). |
|---|---|
| Type | Flow, Context, Global, Business Process, ODS Global, ODS Local, or Environment. |
| Dyn | If checked, the variable name is itself an expression. |
| Name | The target variable name. (For ODS deletes, leave blank to clear all.) |
| Data Type / Encoding / Index | Type and encoding metadata; Index is the position inside an ODS array. |
| Update Expression | The value (an expression) to write. |
| Condition | Boolean expression that decides whether the action runs. |
Using the Flow Data Utility
You'll need two new variables — one per scope:
- Under the Scan for New Requests flow, double-click Flow Variables and add
F.RequestNum— Numeric, size 5. - 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:
- Drop Flow Data as a child of Check if the Customer Exists. Name it Get Req number from FileName.
- Open its configuration and click Add twice to add two commands:
| Action | Type | Name | Update Expression |
|---|---|---|---|
| Update | Flow | F.RequestNum | Val (Mid (Right (Trim (F.RequestFileName), 7), 1, 3), '5') |
| Update | Context | C.All_Items_Exist | 'TRUE'log |
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 Local | Saved per-thread; cleared when that thread completes. |
|---|---|
| ODS Global | Saved 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:
- Open the Get Req number from FileName step's configuration.
- Click Add.
- Fill in the row:
| Action | Type | Dyn | Name | Data Type | Update Expression |
|---|---|---|---|---|---|
| Insert | ODS Global | checked | 'Request_' & Trim(Str(F.RequestNum,'5')) | BLOB | F.RequestXML |
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.
- Right-click Business Process-1 and choose Add Flow. Rename it to Check Item.
- Add three flow variables:
F.ItemCode(Alpha 30),F.RequestNum(Numeric 5),F.Quantity(Numeric 9.2). - Drop a Data Mapper step in the flow and name it Report Items Existence.
- Source: a Database source named CheckItem — Products table, StockQuantity column, WHERE
[Products].ProductCode = '<?F.ItemCode?>'. - Destination: a Variable destination named Update_General_Check_Var bound to
C.All_Items_Exist. - Connect
StockQuantitytoC.All_Items_Exist. - On the destination node's Calculated Value, enter:
Src.S1/Record/StockQuantity >= F.Quantity AND C.All_Items_Exist.
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.
- On the Scan for New Requests flow, drop a Data Mapper as a child of Get Req number from FileName. Name it Check Items.
- Add an XML source named Items_from_Request; XSD
course_data\schemas\request.xsd; Source Type Variable; VariableF.RequestXML. - Add a Call Flow destination named CheckEachItem targeting the Check Item flow.
- 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.
- Inside the item node connect
partNum → F.ItemCodeandquantity → F.Quantity. - On
F.RequestNumin the destination, set Calculated Value toF.RequestNum— this passes the parent flow's request number into the called flow.
Exercise
- 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.
- Insert the request into the local MSSQL tables — the request header into
Requests(setCustomerExistsusing whetherF.CustomerNameis blank), and each line intoRequestItemswithStatus = 'TRUE'Logfor valid lines and'FALSE'Logotherwise. - 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.
