|
|
trgr:create-trigger(
|
|
$trigger-name as xs:string,
|
|
$description as xs:string?,
|
|
$event as element(),
|
|
$module as element(trgr:module),
|
|
$enabled as xs:boolean,
|
|
$permissions as element(sec:permission)*,
|
|
[$recursive as xs:boolean]
|
| ) as xs:unsignedLong |
|
 |
Summary:
Creates a new trigger in the context database.
Returns the trigger ID of the created trigger.
|
Parameters:
$trigger-name
:
A unique name.
If $trigger-name is not unique, an error is returned.
|
$description
:
A description of the
trigger.
|
$module
:
The module to execute when the triggering event occurs. Use
trgr:trigger-module
to construct this element.
|
$enabled
:
Set to true if the trigger is enabled.
|
$permissions
:
A sequence of permissions for the trigger. These permissions will determine
which roles are permitted to modify the trigger.
|
$recursive
(optional):
Set to true if the trigger should be allowed to trigger itself for
recursive changes on the same document. Set to false to prevent
the trigger from triggering itself. If this parameter is not
present, then its value is true.
|
|
Required Privilege:
http://marklogic.com/xdmp/privileges/create-trigger
|
Usage Notes:
Triggers should be created in the database defined as the triggers
database for the database in which the documents are stored.
The xdmp:triggers-database function returns the ID of
the triggers database (when run against the database in which the
content is stored). The triggers are created in the
http://marklogic.com/xdmp/triggers/ directory, with
the ID of the trigger completing the URI.
Once a trigger is created, you can view it in the Admin Interface
under the database in which the content is stored, in the Triggers
Summary page (Databases > content_db_name >
Triggers).
|
Example:
xquery version "0.9-ml"
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy"
trgr:create-trigger("myTrigger", "Simple trigger example",
trgr:trigger-data-event(
trgr:directory-scope("/myDir/", "1"),
trgr:document-content("create"),
trgr:post-commit()),
trgr:trigger-module(xdmp:database("test"), "/modules/", "log.xqy"),
fn:true(), xdmp:default-permissions() )
=> The ID of the newly created trigger. This
trigger fires when a document is created in
the /myDir/ directory, and then it spawns the
/modules/log.xqy XQuery document (in the modules
database for App Server against which the document
was created) is placed on the task server to
evaluate.
|
|
|