-
Notifications
You must be signed in to change notification settings - Fork 16
JavaScript Modules
JavaScript modules are supported with Marklogic 8 or greater and can be used in place of an XQuery module. However, if returning multiple values (ex: URIS-MODULE), values must be returned as a ValueIterator. MarkLogic JavaScript API has helper functions to convert Arrays into ValueIterator (xdmp.arrayValues()
) and inserting values into another ValueIterator (fn.insertBefore()
).
JavaScript module must have an .sjs file extension when deployed to Modules database. However, adhoc JavaScript modules support both .sjs or .js file extensions.
For example, a simple URIS-MODULE may look like this:
var uris = cts.uris()
fn.insertBefore(uris,0,fn.count(uris))
To return URIS_BATCH_REF, we can do the following:
var uris = cts.uris()
fn.insertBefore(fn.insertBefore(uris,0,fn.count(uris)),0,"batch-ref")
Note: Do not use single quotes within (adhoc) JavaScript modules. If you must use a single quote, escape it with a quote (ex: ''text'')