Loading TOC...


   $name as String,
   $value as Sequence
) as Sequence


Sets the value of a named server field. A server field is created with xdmp:set-server-field and stores a name/value pair in memory. The server field is available on the App Server in which it is set on the host in which the App Server runs, via xdmp:get-server-field; a server field that is set on one App Server is not available on other App Servers on that host or on the same App Server running on another host.

$name The name of the server field.
$value The value of the server field. If you pass in a single value, it is treated as a Sequence with that single item; therefore, if you pass in an array, the array is treated as a single value (not as one value for each item in the array). If you mean to pass in the values of each item in the array, then you can call xdmp.arrayValues on the array.

Required Privileges


Usage Notes

If you use a server field with the system Plugin Framework (by placing the xdmp:set-server-field code in a main module under the Plugins directory on a host), then the server field will be populated for each App Server on the host before the first request against each App Server is run.

If you set a server field to the empty sequence, it deletes the server field and it will not appear when you run xdmp:get-server-field-names.

If you set a session or server field to a value that comes from a database node (for example, from the value of a search or the fn:doc function), then that session or server field expires after the request time limit (10 minutes by default). These fields expire because they contain references to stands in the database, and as long as those references exist the stand cannot be reclaimed (merged). To keep such a node in a session or server field, make a copy of the node before adding it to the session or server field instead of using the node directly from the database.


xdmp.setServerField("foo", "bar");
=> "bar"

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.


The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • Hi, If I store a javascript object to server-field, is serialization-object stored? Because when I use xdmp.getServerField to get it, I cannot call his function. And if serialization-object stored, did it deserialized every time when I get it?
    • I asked around and here's what I found out: "xdmp.setServerField takes a MarkLogic Value object. "If he passes in a JavaScript object to xdmp.setServerField, the JavaScript object gets converted to a MarkLogic Value object and stored in the server field. If the object is a function or contains a function, a serialization of the function (function name, script origin etc) is stored in the Value object and cannot be converted back to the original function. When he calls xdmp.getServerField, the Value object is converted back to a JavaScript object, but the function becomes a string."
      • Yes, how much time will be spent during conversion process? Is there any info about efficiency of conversion? If javascript object is enough big, will it increase the conversion time? And are there any other way for keep javascript object in server-context-level memory?
        • I would expect it to be fast, but I really don't know. From your question on the tokenize page, I don't think this is the approach you should take anyway.