Reputation: 223
error: [javascript] JS-JAVASCRIPT: let instance = Completed.extract-instance-CompletedObjectives(source); -- Error running JavaScript request: ReferenceError: instance is not defined:
My Code:
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']});}
Is in the modules database:
es-gs/CompletedObjectiveEntity-1.0.0-conv.xqy
The output error is
Stack Trace At line 7 column 33: In
let instance = Completed.extract-instance-CompletedObjectives(source);
- 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(
The name of the function is
declare function completedObjectives:extract-instance-CompletedObjectives()
I used the instance generator to create the module:
const es = require('/MarkLogic/entity-services/entity-services.xqy');
const ARTIFACT_DIR = '/data/modules/';
const desc = cts.doc('/es-gs/models/CompletedObjective.entity.json');
xdmp.save(ARTIFACT_DIR + 'CompletedObjectiveEntity-1.0.0-conv.xqy', es.instanceConverterGenerate(desc));
Can anyone point me in the right direction?
Upvotes: 1
Views: 123
Reputation: 223
I changed line 7 in the original code above to:`let instance = Completed'extract-instance-CompletedObjectives';``
Upvotes: 0
Reputation: 66783
Change line 7 of your code to:
let instance = Completed.extractInstanceCompletedObjectives(source);
When you import the Entity Services XQuery module in a JavaScript module, even though the XQuery methods have kebab-case in the source, they will be exposed and available using camelCase names:
https://docs.marklogic.com/guide/entity-services/getting-started#id_pgfId-1117445
Invoke the functions using their JavaScript-style, camel-case names. For example, in the case of the Person entity type, the module converter functions can be invoked from Server-Side JavaScript using the following names, assuming the module is represented by a variable named person, as shown in the above require statement.
person.extractInstancePerson
person.instanceToEnvelope
person.instanceToCanonical
You can verify the method names exposed with camelCase by executing the following:
const Completed = require('/es-gs/CompletedObjectiveEntity-1.0.0-conv.xqy');
let functionNames = [];
for (const property in Completed) {
functionNames .push(property);
}
functionNames;
Upvotes: 2