Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

declareUpdate in JavaScript calling XQuery in MarkLogic 8

Tags:

marklogic

I try to use the function declareUpdate(); I copy/paste the code from the manual and I get the following error message.

There must be something about this that I am missing. I've added the declareUpdate because of this error:

{error: "XDMP-UPDATEFUNCTIONFROMQUERY: xdmp.apply(create-source#3, "CS_wifi.json", "cswifi", {"getId":{}, "findSource":{}, "createSourceWithMap":{}, "buildSo...}) -- Cannot apply an update function from a query"}  

With the declareUpdate I get this:

{
  "errorResponse": {
    "statusCode": 400,
    "status": "Bad Request",
    "messageCode": "JS-JAVASCRIPT",
    "message": "JS-JAVASCRIPT: declareUpdate(); -- Error running JavaScript request: Operation not allowed on the currently executing transaction with identifier declareUpdate"
  }
}

/**
 * @name vriendingest 
 * This REST extentsion provides SOAP service for the shipment data
 */

declareUpdate();

var eput   = require("/MarkLogic/rest-api/lib/endpoint-util.xqy");
var link   = require("/ext/obi/lib/link-lib.xqy");
var object = require("/ext/obi/lib/object-service-lib.xqy", "/ext/obi/lib/object-lib.xqy");
var source = require("/ext/obi/lib/source-lib.xqy");

function post(context, params, input) {
    try {
      xdmp.log('title')
      xdmp.log(params.title);

      testing  = source.buildUri('takethisuri');
      title    = params.title;
      dataset  = "cswifi";
      sourceId = source.createSource(title, dataset, source);

      xdmp.log(sourceId);

   response = '{success: "' + testing + '"}';
   }
   catch(err){
      response = '{error: "' + err + '"}';
   }
   context.outputTypes = ["application/xml"];
   context.outputStatus = [200, "OK"];

   return response;
}

// Main
exports.POST = post;
like image 806
Thijs Avatar asked May 15 '26 15:05

Thijs


1 Answers

POST calls to extension get the query mode by default. With XQuery you can add a annotation to the POST function to change that, but there is no annotation for ServerSide JavaScript. You best switch to PUT method..

HTH!

like image 131
grtjn Avatar answered May 19 '26 03:05

grtjn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!