Checking Request Status
Some integrations need a human in the loop. This lesson teaches you how to trigger a flow externally, build a dynamic HTML response, and use Magic xpi templates to merge data into a response page — the building blocks of a human-intervention process.
Magic xpi Triggers
A flow can start in many ways. The Trigger area of the Flow Editor lets you wire it up:
- Set Auto Start on the flow to launch it when the project loads.
- Have it called from another flow.
- Subscribe it to a publication (covered later).
- Schedule it (covered later).
- Trigger it on an external event — the focus of this lesson.
Components that can act as triggers include:
- Directory Scanner, Email, HTTP
- JMS, MSMQ, WebSphere MQ
- Web Services, Salesforce, SAP B1
The Human Intervention Process
When a request can't proceed automatically — the customer doesn't exist, an item is short, etc. — the process pauses. Information is persisted (you've already used the database and the ODS for this), and the flow waits for a human response. When the response arrives, the process resumes from the pause point with all relevant context restored.
In this lesson you'll build the response side: an HTTP-triggered flow that returns an HTML page with the customer details and request status. If the customer doesn't exist, the customer ID is rendered as a hyperlink that the user can click to add the customer.
Setting Up the HTTP Trigger
Create the flow and its variables first:
- Right-click Business Process-1 and choose Add Flow; name it Check Request Status.
- Add the following flow variables:
F.HTTP_Request_Num(Numeric 5),F.CustomerId(Numeric 12),F.CustomerExists(Logical),F.RequestExists(Logical, default'FALSE'LOG),F.RequestHeader(Alpha 255),F.Result_HTML(BLOB). - In the Settings dialog under General Environment » User Environment Variables, add
templateswith value%currentprojectdir%course_data\templates%sl%.
Now drop the trigger:
- Drag the HTTP component from the Toolbox into the Triggers area of the Check Request Status flow.
- Name the trigger Receive HTTP Calls.
- In the Setting section, pick the RequestConfirmation service.
- Open the trigger's configuration. In Endpoint Name select
check_request_status. - Map the
RequestNumargument toF.HTTP_Request_Num; set the Return Value toF.Result_HTML.
Building the HTML Header
The HTML response is built up in F.RequestHeader and finally
composed into F.Result_HTML. Start with a Data Mapper step
that fetches request metadata:
- Add a Data Mapper as the first step in Check Request Status; name it Get Information from DB.
- Source: a Database source named Scan_Requests using the Course Database resource. Use the wizard to select Requests, columns CustomerID and CustomerExists, with
WHERE [Requests].RequestId = <?F.HTTP_Request_Num?>. - Destination: a Variable destination named Create_HTML_Header bound to
F.RequestExists,F.CustomerExists,F.CustomerId,F.RequestHeader. - Map
CustomerId → F.CustomerIdandF.RequestHeader; mapCustomerExists → F.CustomerExistsandF.RequestHeader. - On
F.RequestExists, set Calculated Value to'TRUE'LOG— if any record is fetched, the request exists.
For the F.RequestHeader calculated value, build the conditional hyperlink:
IF (Src.S1/Record/CustomerExists, '', '<a href="http://localhost/Magicxpi4.5/MgWebRequester.dll?appname=IFSmagic_xpi_course&prgname=HTTP&arguments=-ARequestConfirmation%23add_customer&RequestNum=' & Trim (Str(F.HTTP_Request_Num,'5')) & ' ">' & Trim (Str (Src.S1/Record/CustomerID, '9')) & '</a>')
Translation: if the customer exists, render nothing; otherwise wrap the
customer ID in an add_customer link. Note the add_customer
endpoint — you'll create it in a later lesson.
Filling In the Customer Details
- Add a Data Mapper as a child of Get Information from DB; name it Get Customer Information.
- Source: Database source named Fetch_customer — Customers table, CustomerName column, with
WHERE [Customers].CustomerID = <?F.CustomerId?>. - Destination: Variable destination named Create_HTML_Header, bound to
F.RequestHeader. - Connect
CustomerName → F.RequestHeader. - On
F.RequestHeader, set Calculated Value to:IF (F.CustomerExists, Src.S1/Record/CustomerName, F.RequestHeader).
When the customer exists, the database name overrides the header; when the customer doesn't exist, the hyperlink built in the previous step remains.
Templates
A template is a file with placeholders that the Data
Mapper replaces with real values, very much like word-processor mail
merge. Templates ship for the course in
course_data\templates; you'll be using
RequestStatus.tpl.
Magic xpi tags use the form <\!$Token_name>:
<\!$MG_name> | A simple placeholder. Appears as a node in the Data Mapper destination schema. |
|---|---|
<\!$MGREPEAT> | Start of a repeat block (compound in the Data Mapper). Repeats once per occurrence. |
<\!$MGENDREPEAT> | End of a repeat block (not a node). |
<\!$MGIF_name> | Conditional block start — included when the named logical value is True. |
<\!$MGELSE> | Optional ELSE block. |
<\!$MGENDIF> | End of an IF block (mandatory if you started one). |
Exercise
- Add a Template destination to merge
F.RequestHeaderand request items intoRequestStatus.tpl; assign the result toF.Result_HTML. - If the request was not found, return a static HTML response page (
RequestNotFound.htm) using the File Management component. Define a new environment variableFiles=%currentprojectdir%course_data\Files%sl%. - Test the flow using the HTML page you generated in the previous lesson — it lives under
%currentprojectdir%Service\RequestConfirmation.
Summary
You should now be able to:
- Describe Magic xpi triggers and the situations they cover.
- Configure an HTTP trigger and bind its arguments to flow variables.
- Build a dynamic HTML response using the Data Mapper.
- Use templates with merge tags to compose richer responses.
