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

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...