Community

MarkLogic 10 and Data Hub 5.0

Latest MarkLogic releases provide a smarter, simpler, and more secure way to integrate data.

Read Blog →

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)