Solutions

MarkLogic Data Hub Service

Fast data integration + improved data governance and security, with no infrastructure to buy or manage.

Learn More

Learn

Stay On Top Of Everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Community

Stay On Top Of Everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

Company

Stay On Top Of Everything MarkLogic

Be the first to know! News, product information, and events delivered straight to your inbox.

Sign Me Up

 
Knowledgebase:
Invoking library modules from a trigger module
25 April 2018 08:41 AM

Introduction

MarkLogic server provides pre-commit or post-commit triggers and these triggers listens for certain events to occur and then invokes a configured XQuery module to run after event occurs. It is a common use case to create a common function in a library module which is shared among different trigger modules called by various triggers. This article shows an example to create and use such a shared library module in a post-commit trigger.

Example

This example shows a simple post commit trigger that fires when a new document is created.

1. For this example create a database 'minidb' and after that set its triggers database as self (minidb). Also, create another database 'minimodule' to store all modules.

2. Using Query Console, create a trigger using trigger definition by evaluating below XQuery against triggers database (minidb)

3. Create a module by running below XQuery against modules database:

4. Insert a library module into the modules database (minimodules):

5. Now insert the sample document into the content database (minidb):

6. Check output in logs:

After a new document having its URI prefixed with "/mini" is inserted into the content database, TaskServer Logs file logs the below message:

2018-04-25 11:40:50.224 Info: *****Document with /mini root /mini/test-25-1-1.xml was created.*****2018-04-25T11:40:50+05:30

NOTE: Module imports are relative to root.

References:

1. Creating and Managing Triggers With triggers.xqy - https://docs.marklogic.com/guide/app-dev/triggers

(0 vote(s))
Helpful
Not helpful

Comments (0)