[InterSystems IRIS for the First Time] Interoperability: Creating Components (Business Process)
Tags: beginners, programming, tutorial, interoperability
Published: 2022-11-29 19:44:51

**This article is a continuation of <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-creating-components-business-operation" target="_blank">this post</a>.**

In the <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-creating-components-business-operation" target="_blank">previous article</a>, we discussed business operations' creation from the components required for system integration.

In this article, you will learn how to create a business process that calls the two business operations you have defined in the sequence order.

* <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-what-prodction" target="_blank">Production</a>
* <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-message" target="_blank">Message</a>
* **<span style="background-color:#f1c40f;">Components</span>**
  * Business Services
  * **<span style="background-color:#f1c40f;">Business Processes</span>**
  * <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-creating-components-business-operation" target="_blank">Business Operations (previous post)</a>

The business process acts as the coordinator (command center) of the process.

The processing adjustments you may want to implement in the sample include the following:

<p style="margin-left: 40px;">
Step 1: Provide the <u><strong>city name</strong></u> to an external Web API and request <span style="color:#c0392b;"><strong>weather information</strong></span>.<br />Step 2: Register the result of the query (<span style="color:#c0392b;"><strong>weather information</strong></span>) from Step 1 and the name of the purchased product received at the start of the production.
</p>
In the sample business process, we will wait for the answer to step 1 and adjust step 2 to operate.

In the process of waiting for a response (i.e., synchronization), for instance, what happens if step 1) doesn't respond for a few days?

If new messages are delivered to the business process while waiting for a response for a few days, the messages will not be dismissed since they are stored in a <span style="color:#2980b9;"><strong>queue</strong></span>. However, the business process will not process new messages, and there will be a delay in the operation.

<p style="margin-left: 40px;">
  Note: Business processes and business operations have cues.
</p>

Therefore, in production, when there is a synchronous call, there are two ways for the business process to move: **<span style="background-color:#f1c40f;">A) to synchronize perfectly</span>**, and <span style="color:#ffffff;"><strong><span style="background-color:#1abc9c;">B) to save the state of the business process itself in the database and hand over the execution environment so that other processes can run while waiting for a response.</span> </strong></span>

**<span style="background-color:#f1c40f;">A) How to synchronize perfectly:</span>**
<p style="margin-left: 40px;">
While a synchronous call is being made, the business process's processing is ongoing, and waiting for the next message to be processed until all processing is completed.<br />&#x27a1;This function is used when the order of processing needs to be guaranteed in the first-in-first-out method.
</p>
<span style="color:#ffffff;"><strong><span style="background-color:#1abc9c;">B) The method of saving the state of the business process itself in the database and hand over the execution environment so that other processes can run while waiting for a response</span></strong></span> is

<p style="margin-left: 40px;">
When a synchronous call is made, the process saves its state in the database. When a response message is received, and it is time to process the message, it opens the database and executes the next process.<br /> (IRIS will manage the storage and re-opening of business processes in the database). <br />&#x27a1; Used when it is acceptable to switch the processing order of messages (i.e., when it is allowed to process more and more different messages received while waiting for a response).
</p>

In the sample, **<span style="color:#ffffff;"><span style="background-color:#1abc9c;">B)</span></span>** is used.

There are two types of editors for creating business processes: a Business Process Editor that allows you to place processing boxes (activities) and implement them while defining their execution, and a method for creating them using ObjectScript in Studio or VSCode.

If you use the Business Process Editor, you will use the call activity to invoke the component, but this activity is **implemented** in the **<span style="color:#ffffff;"><span style="background-color:#1abc9c;">B)</span></span>** way. **Of course, you can also implement the** **<span style="background-color:#f1c40f;">A)</span>** method in the Business Process Editor, except that you will not use the call activity in that case (you will use the code activity).

In this section, I will explain how to create it.

If you use the Business Process Editor, you write them in the Management Portal.

You can also open the business process from the production configuration page. The figure below shows the procedure.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ooyr7p7vy3dslmt641zq.png)

Icons like ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2sk9e0b6fnk0ke4bx48.png)  in this editor are called activities, and those marked with <call> are activities that can invoke other components.

This symbol ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxdk7dongkbtpbjw6vd8.png)  indicates that a response message will be returned (i.e., a synchronous call will be made). The <call> activity defaults to the asynchronous call setting, which can be changed as needed.

Now let's look at business processes, which are components that are invoked upon receiving a request message, as well as business operations.

In the sample, the request message: It is set to start when it receives a <a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Request.cls" target="_blank">Start.Request</a> and does not return a response message.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1uw4lyvfwq79o31namnq.png)

In the business process, messages appear in various situations.

<p style="margin-left: 40px;">
Request messages that are sent to business processes.
</p>

<p style="margin-left: 40px;">
<call> Request message (+ response message) to be sent when calling another component using the activity.<br /> 
</p>

In the Business Process Editor, the names of the objects that store messages are clearly separated to be able to see which message was sent from which destination.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bl1k330o31jdknk6roq7.png)

* request（basic requirements）

<p style="margin-left: 40px;">
The message that triggered the start of the business process, in our example, is <a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Request.cls" target="_blank">Start.Request</a> (the message to be specified in the Request settings on the Context tab in the Business Process Editor)
</p>

* response（basic response）

<p style="margin-left: 40px;">
Response message to return to the caller of the business process (not used in the sample) (message to be specified in the settings of the response in the context tab in the Business Process Editor)
</p>

* callrequest（request message）

<p style="margin-left: 40px;">
Request message to be sent when calling the component determined by the <call> activity.
</p>

* callresponse（response message）

<p style="margin-left: 40px;">
Response message returned from the component specified by the <call> activity.
</p>

**callrequest and callresponse are objects that will be deleted when the call processing of the <call> activity is completed.**
All other objects will not disappear until the business process is finished.

Now comes the problem when callresponse disappears.

That's because, as you can see in this sample,
**<span style="background-color:#ecf0f1;">When calling a component, if you want to use the response result of a previously called component, the response message will be lost, and the information that was to be used in the next component will be erased.</span>**

It is a problem &#x1f613;

What should we do?・・・・・

In such a case, you can use the context object.

The context object, like request/response, is an object that survives until the end of the business process.

Moreover, since context is a generic object, it can be defined in the process editor.

In addition to the context, the response object can also be used if it has a property that matches the inherited data's saving.

Now, let's go over the steps again.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5i7mr1hsdp9qlobautq1.png)
 
Response message in the <span style="color:#3498db;"><strong>light blue balloon</strong></span>: <a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Response.cls" target="_blank">Start.Response</a> is an object that will be deleted when the process is finished.

Since we want to use the response message (<a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Response.cls" target="_blank">Start.Response</a>) that contains the weather information as the message to be sent to the next [Business Operation for DB Update], we have to implement the context object in a way that all the property values of the response message (<a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Response.cls" target="_blank">Start.Response</a>) can be assigned to it.

Then what is the setting for the context property?

The properties are defined in "Context Properties" in the Context tab of the Business Process Editor.

In this case, we would like to save all the properties of the response message (<a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Response.cls" target="_blank">Start.Response</a>) to the context object. Therefore, the property type specification is set to <a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/Response.cls" target="_blank">Start.Response</a>.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a824s9gm7c01kh1ogeo4.png)

Following that, check the settings in the <call> activity.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2w4h9ibhld1n3ky5xcnx.png)

The request and response messages have a button called ○○ Builder.

Clicking on this button will launch a line-drawing editor that allows you to specify what you want to register in the properties of each message.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1f5hc2ff3lvv4g6w52m.png)

After this, the business operation for requesting a database update (<a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/SQLInsertOperation.cls" target="_blank">Start.SQLInsertOperation</a> or <a href="https://github.com/Intersystems-jp/selflearning-interoperability/blob/master/src/Start/InsertOperation.cls" target="_blank">Start.InsertOperation</a>) is called in the same way with the <call> activity, and you are all set.

(For more information, see Configuring 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/89oo5n3cpwg8ksduzmwu.png) for Business Processes).

Once you have completed the verification, you can test it. The testing method is the same as the one used for testing business operations (see <a href="https://community.intersystems.com/post/intersystems-iris-first-time-interoperability-creating-components-business-operation#test" target="_blank">this article</a>).

The trace after the test is as follows:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2cbgmec8o5vvzozlco5.png)

Since the business process is the coordinator, we could see that it invoked the defined components sequentially, keeping the synchronous execution.

<p style="margin-left: 40px;">
Note 1: The sample only deals with the call activity, but various other activities such as data transformation.
</p>

<p style="margin-left: 40px;">
Note 2: Business processes created by ObjectScript alone, other than the Business Process Editor, inherit from the Ens.BusinessProcess class. If it is created in the Business Process Editor, it inherits from the Ens.BusinessProcessBPL class.
</p>

<p style="margin-left: 40px;">

</p>

<p style="margin-left: 40px;">
  <img src="https://community.intersystems.com/sites/default/files/inline/images/images/image(1078).png"/>
The business process is the coordinator of the system integration process.<br />The Business Process Editor provides the following types of variables for messages (request/response/callrequest/callreponse/context).<br />A business process created with the Business Process Editor can work in a way that does not delay other messages, even if there is synchronization in the component's calling.
</p>

In the next section, we will finally show you how to develop the last component: business services.