Can we call a JavaScript function from Pega activity/DataTransform?
The answer is YES but there is no OOTB feature provided by Pega to fulfil this. There mught be various options to achieve this functionality but I am exlaining here to crack it by using java code written in a simple Pega function. This Pega function would act like a wrapper to cover the java logic and can be called in not only just activity/DT call but wherever we have a possibility. Java has a package called "javax.script.*" where we have all the invocation methods to run the JS code. This code is tested in Pega V7.x and V8.x but I am not 100% sure about prior versions of Pega. The idea behind this tiny exercise is like we call a js file (SampleJS.js) from the server path (eg:/tomcat/lib)and execute the JS function within the server to get the o/p value from the function logic.
Here are the simple steps to be followed in implementing this work.
1) Create a Pega function(eg:RunJSFunction) having a parameter of js file location (/tomcat/lib/misc/SampleJS.js)
2) Call the above from an activity(eg:RunJSFunction) by passing the js file path from a DSS rule (eg:JSFilePath)
3) Get the return value from the JS function written in that SampleJS.js file and store it in a parameter (eg:JSReturnVal)
4) Display the parameter using Show-Property.
Here is the snapshot to understand the above steps clearly. It is very easy and may be useful in few instances.
Note: Pega function code will be given upon request and is prohibited to publish on this blog.
References:
1) google.com
2) stackoverflow.com
3) Pega PE
