Tuesday, November 10, 2015

JavaScript and PeopleCode Array Parameters

I have been experimenting with scripting PeopleCode using JavaScript. This is possible because Java includes Mozilla's Rhino JavaScript engine. I took one of my experiments to OpenWorld 2015 which shows creating a Microsoft Excel Spreadsheet using POI and JavaScript. Here we are, a couple of weeks later, and I see this in the PeopleSoft OTN Discussion Forum: Java Exception: java.lang.reflect.InvocationTargetException: during call of java.lang.reflect.Method .invoke. Perfect! That is my exact use case from OpenWorld. I just happen to have a code sample to share on the forum. The developer's scenario was a bit more complicated. As you will note from the forum post, the developer needed to invoke SQL.Fetch from JavaScript. The JavaScript version of SQL.Fetch, which uses the PeopleCode Java interface, requires an array of selected columns. My first thought was just to use a standard JavaScript array. Since the SQL only has one column, I just needed an array with one item. This didn't work. JavaScript Arrays clearly are not Java Arrays. Here is an example:

var result = (function() {  
    var ReflectiveArray = java.lang.reflect.Array;  
    var CreateSQL = Packages.PeopleSoft.PeopleCode.Func.CreateSQL;  
    var columns = ReflectiveArray.newInstance(java.lang.Object,
        1 /* number of selected columns */);  
    var results = [];  
    while (SQL.Fetch(columns)) {  
    return results.join();  


Manish Sharma said...

Hi Jim and Sasank,

At last i am able to complete this requirement!! Thanks a Lot for your guidance and support!

i have used another class of Apache POI to create the large file as Packages.org.apache.poi.xssf.streaming.SXSSFWorkbook; and it works great and we can create really a large file with no Memory issues or anything like that. even i have created a generic class now in Peoplecode to create Excel reports through Application Engine, to avoid Microsoft OLE Automation issues, and to reduce the memory processing issues.

var result = (function() {
// import statements
var SXSSFWorkbook = Packages.org.apache.poi.xssf.streaming.SXSSFWorkbook;
var FileOutputStream = Packages.java.io.FileOutputStream;
// variable declarations
var workbook = new SXSSFWorkbook();
var sheet = workbook.createSheet("Countries");
var fileName = "/psoft/fs9devt/UserUpload/ap/real123.xlsx";

for (i = 0; i < 130000; i++) {
var row = sheet.createRow(i);
for(t=0; t < 10; t++){
var cell = row.createCell(t);
cell.setCellValue(t+" in the "+i);
var fos = new FileOutputStream(fileName);

return "Created workbook " + fileName;



Matt and Alissa said...

I wonder when PeopleSoft will run on Java 8? We are writing a ton of client side javascript using React, and would love to the Nashorn Javscript Engine to render them on the server side. See http://augustl.com/blog/2014/jdk8_react_rendering_on_server/ for an example of what I'm talking about.

Jim Marion said...

@Matt/Alissa, I complete agree and have been thinking the same thing. I'm sure you are familiar with project Avatar?

Nalini said...

Hi Jim,
This information is very helpful. Thank You !!
On another note, I created an iscript for a form using javascript in PS Recruiting module for external candidates to enter their additional details when they encounter tech issues. We are on pt8.55 and hcm 9.2. I am hearing there are security concerns when using iscripts thru peoplesoft. Since you had created so many javascript related custom items and shared on this site. Could you please confirm the concerns or look abouts that I should be really aware of.

Thank you for your help!!

Jim Marion said...

@Nalini, iScripts have no security concerns by themselves. iScripts use role/permission list security just like anything else in PeopleSoft. It is really about the code within the iScript. It is important that the person writing the iScript keep security top of mind.

Shiva said...

Hi Jim,
I thought you may come across this situation so just needed your guidance.
We were using 8.5 tools and old application 8.4.
Question is, i want to hide the PeopleSoft delivered buttons(save, Next,previous) on each page of component for particular customers depending on their status. How can we do this?

Tried Option: I just tried a blind script on page activate through #ICSAVE Id through hidden property but not worked.I suppose the script is executing before the page formation.

If I uncheck the component property it will affect all customers.

Any Idea on how to achieve this req?


Jim Marion said...

@Shiva, you are correct. You could write JavaScript to hide buttons, but the problem is that anyone can use their browser to unhide or activate buttons, etc. It would just be cosmetic, not secure.