I'm new to xsjs and xsjslib and my task seems to involve using xsjs files and possibly xsjslib files too. Here is the app I'm building: A user enters some inputs on the front end, clicks a button and a job gets scheduled to run later in the day. The job is to take those inputs, make a call to a calculation view which will retrieve some data and store it as an excel file. My problem is that based on all the examples I've seen I have to use an xsjs file that the xsjob can call. But from my very little experience with xsjs there are many limitations to what I can do with it. For one, I can't find a way to import external libraries. In an SAPUI5 app I can have a controller and at the top I can define the dependencies like:
sap.ui.define(['path/to/library/', function(library){
...}
Ho can I do something like this with an xsjs or xsjslib file so I can import my excel library?
Sure you can. Just copy the external library js code into a .xsjslib file then use the $.import functionality. You can read about this here: https://help.sap.com/http.svc/rc/3de842783af24336b6305a3c0223a369/2.0.01/en-US/$.html
But it won't work all the time. For instance, I was successful in adding moment js, by copying the moment.js source into a file called moment.xsjslib and then importing like this:
var moment = $.import("cfm.api.lib", "moment").moment;
and then using it like this:
var utc = moment.utc().toISOString();
But I haven't had much luck with lodash for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With