Magic Software
Lesson 12Hands-on · ~35 min

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
Cap. A flow can have up to ten trigger components.

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:

  1. Right-click Business Process-1 and choose Add Flow; name it Check Request Status.
  2. 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).
  3. In the Settings dialog under General Environment » User Environment Variables, add templates with value %currentprojectdir%course_data\templates%sl%.

Now drop the trigger:

  1. Drag the HTTP component from the Toolbox into the Triggers area of the Check Request Status flow.
  2. Name the trigger Receive HTTP Calls.
  3. In the Setting section, pick the RequestConfirmation service.
  4. Open the trigger's configuration. In Endpoint Name select check_request_status.
  5. Map the RequestNum argument to F.HTTP_Request_Num; set the Return Value to F.Result_HTML.
Step vs. Trigger mode. The HTTP component can also be used as a step — in Get/Post/REST modes — to retrieve information from a URL. As a trigger it's the inbound side: a flow starts when a Web request hits the configured endpoint.

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:

  1. Add a Data Mapper as the first step in Check Request Status; name it Get Information from DB.
  2. 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?>.
  3. Destination: a Variable destination named Create_HTML_Header bound to F.RequestExists, F.CustomerExists, F.CustomerId, F.RequestHeader.
  4. Map CustomerId → F.CustomerId and F.RequestHeader; map CustomerExists → F.CustomerExists and F.RequestHeader.
  5. 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

  1. Add a Data Mapper as a child of Get Information from DB; name it Get Customer Information.
  2. Source: Database source named Fetch_customerCustomers table, CustomerName column, with WHERE [Customers].CustomerID = <?F.CustomerId?>.
  3. Destination: Variable destination named Create_HTML_Header, bound to F.RequestHeader.
  4. Connect CustomerName → F.RequestHeader.
  5. 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).
Destination type. In the Data Mapper, choose Template as the destination type to use a merge template.

Exercise

Finish the Check Request Status flow.
  1. Add a Template destination to merge F.RequestHeader and request items into RequestStatus.tpl; assign the result to F.Result_HTML.
  2. If the request was not found, return a static HTML response page (RequestNotFound.htm) using the File Management component. Define a new environment variable Files = %currentprojectdir%course_data\Files%sl%.
  3. 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.