Reference/call SSJS library/function in another database - xpages

In XPages, is it possible to call a function in a SSJS library in another database? I'm trying to include a script resource in my custom control that points to a SSJS library in another db. (I'm trying to avoid duplicating the lib by copying it over.) Per this question, I determined the full path to the library by going to the Package Explorer view.
<xp:this.resources>
<xp:script src="picker.nsf/code/scriptlibraries/mylib.jss" clientSide="false" />
</xp:this.resources>
I tried prefixing the path both with and without a \ or / and also propercasing the path, but I continue to get the following runtime error:
Error while executing JavaScript action expression JavaScript library
/picker.nsf/code/scriptlibraries/mylib.jss is not available
I also tried putting copies of picker.nsf in the root (Domino data folder) and in the same subfolder as the primary db but that didn't work.
I think the source question above refers to a .js file that was attached in the files area rather than a code library so it might not apply. Any ideas?

You need to separate the thinking of serverside js and client side js.
Serverside javascript is not "real" javascript like in Node.js, it does only work in the context of a single database and is at runtime running inside the java engine. There might be some OSGI functionality that can inject the code from another database but nothing that is official supported.
Client side javascript is running in the client browser and can access everything that the client browser can access.

Related

how to get web api in nodejs (without lib)

I am making a module that converts html to json in node environment. I would like to know how to access web browser api from node. How can I access document object with nodejs only without libraries such as cheerio and jsdom?
(I used Google Translate, sorry)
Node.js does not have built-in support for rendering HTML documents.
It doesn't execute JavaScript that it extracts from <script> elements inside an HTML document.
It has no native document object.
If you want one you either need to build it yourself or use a third-party library.

Serve custom javascript to browser via Node.js app

I developed a small node.js app in which I can configure conditions for a custom javascript file, which can be embedded in a webpage, and which modifies the DOM of that page in the browser on load. The configuration values are stored in MongoDB. (For sake of argument: add class "A" to DOM element with ID "B" )
I have difficulties to figure out the best way to serve requests / the JavaScript file.
Option 1 and my current implementation is:
I save a configuration in the node app and a distinct JavaScript
file is created for that configuration.
The page references that file which is hosted and served by the server.
Option 2 and where I think I want and should go is:
I saves a configuration (mongodb) NO JavaScript file is created Pages
a generic JavaScript link (for instance: api.service.com/javascript.js)
Node.js / Express app processes the request, and
returns a custom JavaScript (file?) with the correct values as saved in mongodb for that configuration
Now, while I believe this is the right way to go about it, I am unsure HOW to go about it. Any ideas and advise are very welcome!
Ps: For instance I wonder how best to authenticate or identify the origin, user and requested configuration. Shall I do this like: api.service.com/javascript.js&id="userID" - is that good practice?
Why not serve up a generic Javascript file which can take a customized json object (directly from mongodb) and apply the necessary actions? You can include the json data on the page if you really need to have everything embedded, but breaking up configuration and code is the most maintainable approach.

Can' call XSP functions in XPINC

I try to call XSP._isDirty() for XPINC but it does not work. In the browser everything works fine. Is there a trick how i can use it.
Is there a way how i can see clientside errors when i'm executing XPages in the Notesclient?
Two questions here.
Q1. XSP._isDirty()
XSP._isDirty() is an internal call. From the XPages portable command guide (page 156).
XSP._isDirty() : Used internally by the Dirty Save feature— see the <xp:view> properties for enableModifiedFlag. This is a private function.
Code for this call is in the file xspClientDojo.js (look for the uncompressed file on Domino/Notes).
As it is an internal call it is used at risk. There is no guarantee it will work as expected in later versions.
The enableModifiedFlag is an XPage attribute that allows you to mark the page as dirty and prevent the user accidentally leaving the page. There are more details about this on the Infocenter.
Q2. Client side debugging.
You can review client side errors using the developer panel of most modern browsers, or something like the firebug plugin. The XPages extension library comes with a Firebug Lite component you can use as well.
For SSJS and XSP engine issues you can review these in the Notes client by reading the XPages logs in the IBM_TECHNICAL_SUPPORT folder contained in the Notes data folder.
For a "live" method of this is to modify the shortcut that launches notes as follows:
Target: C:\Lotus\Notes\notes.exe -RPARAMS -console -debug -separateSysLogFiles -consoleLog
Start In : C:\Lotus\Notes\framework\
Change the path to match your clients install.

Include jss file from notes document as resource

The application I am working on needs to perform some SSJS on querySaveDocument of the document. The code it should execute needs to be maintainable without a Designer client (don't ask me why, but it's a customer prerequisite).
The .jss file is stored as file attachment in and I am trying to access it using as a resource of my XPage with a $file url. I tried both http: and notes: with replica id and db path, but the XPages engine can't seem to reference the file.
What would the format be of the "src" attribute if the resource?
Check out this post from Stephan
http://www.wissel.net/blog/d6plinks/SHWL-86QKNM
I think this will help.
I am not sure that this will work. But you could load the library/code with your SSJS or Java method and just do a eval()* or a value binding with the text loaded from your external resource. Then the SSJS code is available for the interpreter and can be executed in the event.
*: eval() is evil! You have been warned!

What technology can i use to run a method on a browser(client side) every time a user uploads a picture?

I have a custom function/method that needs to run on the browser (client side) every time the user uploads a picture to a web-server. This method modifies the image being uploaded and sends it to the server.
Currently the method is written in java so I thought of using an applet on the browser which could run this method and then send the modified picture to a servlet residing on the server, but the applet has certain disk read/write restrictions. I am aware of policies that can be used to grant these permissions to the applet but they need the users consent every time.
Also I want to avoid the applet .class file to be downloaded every time this page is viewed. So
Is there a cleaner approach to all this?
Are there any other technologies that can help me run this method on the browser ? (its ok if i have to rewrite the function in a different language)
Is writing a custom browser extension a good idea?
I think, that the JS using will be much better for this task.
One of JS image processing JS-library
, just for example.
How to invoke a servlet from JS example
Writing a browser extension is a really wrong way.

Resources