Wednesday, September 2, 2020

How to use Libraries in OIC for User Defined Functions

In this Blog, we are going to see how to use Libraries on OIC. We are taking an example of generating random password using JavaScript and expose it as a Function, so it can be used in our Integrations.

JavaScript libraries provide a means to create and organize JavaScript for use in integrations. Library functions are automatically available for you to drag into your orchestration integrations.

Create a JavaScript Library

In order for custom function calls to appear in the integration Actions palette, you must create the libraries that contain them.

In the left navigation pane, click Home > Integrations > Libraries.

Click Create in the banner.



In the Create Library dialog box, click Browse to select a JavaScript (.js) library file.
Specify a name, identifier, version number and optional description.

Note: I have created a JavaScript with one parameter(Length) as input and one parameter(Password) as output. You can get the .js file in this link.



Select the Input and Output type.




Now Click Save and our Custom Function is ready.

Create a new App Driven Integration


Select Rest Connection as Trigger.




Configure it as below.(to accept the request and respond back)


Define Input and Output Parameters as shown below, In our case its JSON sample.




After configuring the trigger you should be able to see the integration flow as below.
Click on Edit Map activity.
Click on Right Toggle functions icon on top-right corner. Under functions-> User Defined, you will be able to see the function we created in Library.


Drag and drop the function onto target field(Password). And configure the input as length from request-wrapper.


And we are done.!!! Save and Activate the Integration to test.

Test Result: