Introduction to Service Call Out in Corticon.js V2.0

Introduction to Service Call Out in Corticon.js V2.0

Posted on May 09, 2023 0 Comments

The Corticon.js V2.0 release introduces a new feature called Service Call Out.

What is It?

Simply put it, a service callout (or SCO for short) is an execution step in a decision service flow that invokes custom JavaScript logic.

Here is a simple ruleflow example where the SCO Call is executing after a specific rulesheet (“Before SCO Call”):

Note: The service call out can happen anywhere in the ruleflow. It could be the first or last step of the entire ruleflow.

What Can It Do?

As custom JavaScript code, the service callout can practically do anything. It has access to the full data payload at the step in which it is invoked. This is the full input data payload as well as all the modifications to it from rules that have executed thus far.

We provide an API to facilitate reading from the payload as well as writing to it. This can be leveraged to enrich the payload with additional data. It is useful for use cases where it is not desirable to pass the data in the input payload in the first place, i.e. when services will only use some of the data in specific execution paths.

Another way to put this is that some services will need to conditionally access additional data based on conditions computed in the decision service. For example, when computing an offer for a solar system installation, you will need access to various configuration pricing data. Instead of passing all the data for all possible configurations for all the regions, it may be more appropriate to have an SCO request the subset of the data the decision service really needs at that point in the execution.

Of course, the SCO can persist portion of the payload to an external data source.

Example usages could be to access data via a REST service or a Database call. Or, it could be to provide some complex financial calculation.

For more information on the API, check the online documentation here.

Getting Started

To get started, we have provided several samples at https://github.com/corticon/corticon.js-samples/tree/master/ServiceCallOut.

Here is a brief run down of the first ones you need to focus on to get started smoothly:

HelloWorld is the simplest SCO. It is at https://github.com/corticon/corticon.js-samples/tree/master/ServiceCallOut/HelloWorld.

It shows the basic mechanics of an SCO.

Next, you should look at the basic sample to update attributes https://github.com/corticon/corticon.js-samples/tree/master/ServiceCallOut/UpdateEntityAttributes.

It is particularly useful to understand how to create non-primitive types like Decimals, DateTimes and Dates. Attributes using primitive types like strings and integers can be updated with JavaScript Strings and JavaScript Numbers respectively.

If your use case requires creating additional entities and relations (for example adding child entities to a parent entity), check this sample: https://github.com/corticon/corticon.js-samples/tree/master/ServiceCallOut/CreateAssociation.

When you need to pass configurable data, you can leverage the access to the configuration properties as illustrated in this sample: https://github.com/corticon/corticon.js-samples/tree/master/ServiceCallOut/AccessConfigurationProperties.

Most likely you will need to access (read or write) data from external data sources. In this case, you will need to understand how to do asynchronous operations. We will cover considerations for doing asynchronous operations in a separate blog but in the meantime, check this sample to get started: https://github.com/corticon/corticon.js-samples/tree/master/ServiceCallOut/BasicAsyncOperation.

There are several additional samples not described here. Check them out at: https://github.com/corticon/corticon.js-samples/tree/master/ServiceCallOut.

Conclusion

The support for either passing all the data in or conditionally accessing data on an as-needed basis at any point in the flow provides maximum flexibility in architecting and designing optimum decision services.

Writing to a data source at any point in the decision service flow also provides architecture flexibility.

Find out here how Corticon as a no-code/low-code environment can help increase your productivity and deliver your solutions faster.

And you can enroll in a free training for Corticon.js here.

Enroll in a Free Corticon Training

Thierry Ciot

Thierry Ciot

Thierry Ciot is a Software Architect on the Corticon Business Rule Management System. Ciot has gained broad experience in the development of products ranging from development tools to production monitoring systems. He is now focusing on bringing Business Rule Management to Javascript and in particular to the serverless world where Corticon will shine. He holds two patents in the memory management space.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation