I am trying to change the document version uri of a unitemporal document while inserting the document in a unitemporal collection.
I am running the below xquery , but it throws me the below error.
XQuery :
xquery version "1.0-ml";
import module namespace temporal = "http://marklogic.com/xdmp/temporal"
at "/MarkLogic/temporal.xqy";
let $root :=
<EDILogFile>
<ID>1234578</ID>
<SystemRef>12344</SystemRef>
<system-Start>(fn:current-time())</system-Start>
<system-End></system-End>
<DateCreated>2022-09-09T19:07:46.3492849+01:00</DateCreated>
<TimeSaved>240</TimeSaved>
<Production>true</Production>
<Partner>Ellerman</Partner>
<MessageType>Invoice</MessageType>
<Fail>false</Fail>
<ManyReasons/>
<SubmissionUser>System</SubmissionUser>
<InternalBusinessUnit>Finance</InternalBusinessUnit>
<Direction>Inbound</Direction>
</EDILogFile>
return
temporal:statement-set-document-version-uri("EDI_22000043.xml","EDI_22000043.v1.xml"),
temporal:document-insert("UnitemporalColl-SysAxesInDoc", "EDI_22000043.xml", $root)
Error :
[1.0-ml] XDMP-UNDVAR: (err:XPST0008) Undefined variable $root
Stack Trace
At line 24 column 78:
In xdmp:eval(" xquery version "1.0-ml"; import module namesp...", (), <options xmlns="xdmp:eval"><database>1754687030342455867</database>...</options>)
return
temporal:statement-set-document-version-uri("EDI_22000043.xml","EDI_22000043.v1.xml"),
temporal:document-insert("UnitemporalColl-SysAxesInDoc", "EDI_22000043.xml", $root)
In the return statement, you have two things that you want to do - but have not wrapped in
()
to indicate that it is a sequence of operations.So, it sees the
temporal:statement-set-document-version-uri()
as the only thing you are returning from that FLWOR statement, then the start of a second FLWOR statement that is justtemporal:document-insert()
function call - but then it complains that it doesn't know what$root
is because it is out of scope (declared in the other FLOWR statement, not this one).So, to execute both functions in the return as part of the same FLOWR, wrap them in parenthesis: