Wednesday, March 10, 2021

OIC - Use of Javascript in Integration | Add two numbers to keep fixed decimal positions

Usecase: Convert 2 numbers and rounding the numbers to keep only three decimals.

Step 1 : Create .js file and import in Libraries

add2NumbersTest.js

    function addTest(num1,num2){

    var newNum;

    var newNum2;

    newNum = parseFloat(num1) + parseFloat(num2);

    newNum2= newNum.toFixed(3)

    return newNum2;

    }

Import Navigation:

Integrations--Libraries--create--choose File --provide library name--create--select function--save







Step 2 : Create an Integration and use the javascript action and test it.

I have created a simple REST trigger connection and created an app driven Orchestration integration and in the REST trigger, I have added relative URL as /addTwoNums, Verb as POST, Configure following two options:

Configure a request payload for this endpoint

Configure this endpoint to receive the response

Input:

{

"num1":123.34567,

"num2":234.34455

}

choose Json as response payload type and  provide inline Json sample

{

"result": "234.56"

}

Add Javascript action and choose the created JS function. and map the two inputs with num1 and num2.

Last map the JS response with the output of the rest service.




















Add Tracking and test



No comments:

Post a Comment

Featured Post

OIC - Sending JSON Data as Email Body Content via Twilio SendGrid API in OIC

Use Case Description: When integrating Oracle Integration Cloud (OIC) with Twilio SendGrid API to send emails, JSON data intended for the em...