Question

Javascript Scripting Code

  • 17 January 2023
  • 5 replies
  • 48 views

Hello,

I am trying to load some excel files and need to parse them through a script. In the javascript code I have used the xlsx libraries and it’s function, but I am not able to use it in my code. Can someone help me with this? Thank you!


5 replies

Userlevel 4
Badge

@groversakshi1998 is it possible to share the pipeline and a link to download this js file so that i can give it a try myself

The file is loaded on the SDC server and the path is pointing to the folder as well. Still it’s not able to find the “require” function 

Userlevel 4
Badge

@groversakshi1998

 

Have you updated $SDC_CONF/sdc-security.policy file and added the required permission?

// Set global perm so that JS can load scripts from this directory// Note - this means any code in the JVM can read this dir!grant {  permission java.io.FilePermission "/folder/file/-", "read";};

Make sure the file is loaded on the SDC server and the path is pointing to the folder on SDC machine.

Hello,

So I tried loading a file, xlsx.js as I require the xlsx library for my script.

When I am using the require function as mentioned in this blog Calling External Libraries from the JavaScript Evaluator | StreamSets

It is giving me error that the require function is undefined.

Can you kindly help me with the same

 

Thanks

Userlevel 1
Badge

Javascript is executed using Nashorn, so it is possible to load extra JavaScript using the “load” function (https://wiki.openjdk.org/display/Nashorn/Nashorn+extensions), but you may need to modify the Security Manager to give it permission to load the files (https://docs.streamsets.com/portal/platform-datacollector/latest/datacollector/UserGuide/Configuration/DCEnvironmentConfig.html#concept_tm4_pbg_ht)

Reply