[javascript] XDMP-CAST: (err:FORG0001) xs:string#1(.) -- Invalid cast: `json:object(<json:object xmlns:xs="http://www.w3.org/2001/XMLSchema" `
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" .../>) cast as xs:string
Stack Trace
In /MarkLogic/entity-services/entity-services.xqy on line 313
In xs:string#1(.)
fn:QName("http://marklogic.com/entity-services","source-nodes") =
fn:doc("/budget/Accomplishments/objective/2019-6.json")/array-node("tasks")/object-node()
fn:QName("http://marklogic.com/entity-services","fn") = xs:string#1`
declareUpdate();
const es = require('/MarkLogic/entity-services/entity-services.xqy');
const Completed = require('/es-gs/CompletedObjectiveEntity-1.0.0-conv.xqy');
for (const source of fn.collection('Objective,Accomplishments')) {
let instance = Completed['extract-instance-CompletedObjectives'](source);
let uri = '/es-gs/env/'+ instance.id + '.json';
xdmp.documentInsert(
uri, Completed.instanceToEnvelope(instance, "json"),
{collections: ['CompletedObjective-envelopes']}
);}
I am struggling to generate instance documents due to an error occurring on a specific line.
let $tasks := es:extract-array($source-node/tasks, xs:string#1)
I don't understand why this error is happening
Sample
{
"goal": "- Launched",
"tasks": [
{
"Task-1": "-- Step 1"
},
{
"Task-2": "-- Step 22"
},
{
"Task-3": "-- Step 33"
}
],
"id": "1"
}
Below is additional code related to task management
I have tried different server options for the code provided below. It successfully builds and deploys the instance, but the tasks within the array are missing