<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.invoke.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.invoke</api:function-name><api:suggest>xdmp.invoke</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>invoke</api:suggest><api:function-link mode="xquery" fullname="xdmp:invoke">/apidoc/8.0/xdmp:invoke.xml</api:function-link><api:function mode="javascript" name="invoke" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.invoke"><api:summary>
  Returns the result of evaluating a module at the given path.
</api:summary><api:params><api:param name="path" type="xs:string"><api:param-description>
    The path of the module to
    be executed as a string.  The path is resolved against
    the root of the App Server evaluating the query, the Modules directory,
    or relative to the calling module.  The module is considered to be
    JavaScript if the module path ends with a file extension matching the ones
    configured for application/vnd.marklogic-javascript in MarkLogic's
    Mimetypes configuration.  For details on resolving paths,
    see "Importing XQuery Modules and Resolving Paths" in the
    <em xmlns="http://www.w3.org/1999/xhtml">Application Developer's Guide</em>.
  </api:param-description><api:param-name>path</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="vars" type="Object" optional="true" class="javascript"><api:param-description>
    The external variable values for this evaluation.
    This can either be a sequence of map:map objects, or a sequence of even
    length, alternating QNames and items.
    <p xmlns="http://www.w3.org/1999/xhtml">Each key in the map(s) is a string representing the name of the parameter
    in Clark notation: "{namespaceURI}localname". The function
    <a href="./xdmp.keyFromQName">xdmp.keyFromQName</a>
    is a convenient way to generate these keys.
    Each entry in the map is the value of the corresponding external 
    variable.</p>
    <p xmlns="http://www.w3.org/1999/xhtml">Alternatively, the alternating sequence should contain QName and item
    pairs that specify a variable name and value for an external variable.</p>
  </api:param-description><api:param-name>vars</api:param-name><api:param-type>Object</api:param-type></api:param><api:param name="options" type="(element()|map:map)?" optional="true"><api:param-description>
  
  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">The options object. The default value is null. See the
  <a href="./xdmp.eval"><code>xdmp.eval</code></a> section for a list of options.</span>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>Object?</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:privilege>
<p xmlns="http://www.w3.org/1999/xhtml"><code>http://marklogic.com/xdmp/privileges/xdmp-invoke</code></p>
</api:privilege><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  xdmp.invoke("http://example.com/modules/foo.xqy")
  =&gt; 2</pre>
</api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  This example invokes a module using external variables.

  Assume you have a module in the modules database with a URI
  "http://example.com/application/log.sjs" containing the
  following code:

  xdmp.log(myvar)

  Then you can call this module using xdmp.invoke as follows:

  xdmp.invoke("log.sjs",
	{myvar: "log this to ErrorLog.txt"},
        {
          modules : xdmp.modulesDatabase(),
          root : "http://example.com/application/"
        });

  =&gt; Invokes a JavaScript module from the modules database
     with the URI http://example.com/application/log.sjs.
     The invoked module will then be executed, logging the
     message sent in the external variable to the 
     ErrorLog.txt log file. </pre>
</api:example></api:function></api:function-page>