3

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?

Stephen S
  • 3,936
  • 2
  • 23
  • 33
polaris
  • 339
  • 2
  • 14
  • 33

1 Answers1

2

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.

danpop
  • 967
  • 13
  • 25
  • I saw this at some point, the problem is that it assumes you have the bare code inside your .xsjslib file. My question was more about importing libraries the way you do in SAPUI5 where you just point to the source whether it is a folder or a url. – polaris Aug 02 '17 at 18:37