title: MarkLogic trigger declaration- What am I doing wrong in this?
body: <p>I am dabbling in MarkLogic and am not having an easy time of it. Recently I have been experimenting with triggers, and it has been going just as poorly. It was my hope that someone here could offer me some advice as to what exactly I am doing wrong here.</p>
  
  <p>Following the MarkLogic Community tutorial at <a href="https://docs.marklogic.com/guide/app-dev/triggers#id_66092" rel="nofollow noreferrer">https://docs.marklogic.com/guide/app-dev/triggers#id_66092</a> I named my database test, and listed it as its own triggers database. I then ran this query against the test database:</p>
  
  <pre><code>xquery version "1.0-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() );
  </code></pre>
  
  <p>Which returned <code>14463004257041262559</code>, and I can confirm that this is the correct URI.</p>
  
  <p>I then defined <code>/modules/log.xqy</code> as instructed using this query:</p>
  
  <pre><code>xquery version '1.0-ml';
  (: evaluate this against the database specified 
  in the trigger definition (test in this example)
  :)
  xdmp:document-insert("/modules/log.xqy", 
    text{ "
  xquery version '1.0-ml';
  import module namespace trgr='http://marklogic.com/xdmp/triggers' 
     at '/MarkLogic/triggers.xqy';
  
  declare variable $trgr:uri as xs:string external;
  
  xdmp:log(fn:concat('*****Document ', $trgr:uri, ' was created.*****'))"
  }, xdmp:permission('app-user', 'execute'))
  </code></pre>
  
  <p>Which I then confirmed existed, and exactly matched the text between the quotation marks.</p>
  
  <p>However, when I ran <code>xdmp:document-insert("/myDir/test.xml", &lt;test/&gt;)</code>, the document was created and nothing else happened. When I opened <code>ErrorLog.txt</code> the text it was supposed to append was not there.</p>
  
  <p>Thinking it may have been that I was looking in the wrong place, I also added <code>fn:doc("/modules/log.xqy")</code>  so that it would show me if it ran, but inserting new documents into the correct directory never prompted any sort of action from the trigger.</p>
  
  <p>I’m hoping that one of your number can show me what I am doing wrong, because this is rather frustrating. I await your aid.</p>