API Connect

 View Only
  • 1.  NO_MODIFICATION_ALLOWED_ERR

    Posted Wed October 27, 2021 05:22 AM
    Hi,
    I'm getting NO_MODIFICATION_ALLOWED_ERR in gateway script.
    I have an API which accepts soap xml where i need to update a value in one of the xml element before it is sent to backend.
    Below is gateway script.
    let xml = apim.getvariable('message.body')
    xml.item(0).getElementsByTagNameNS(namespace,'Request').item(0).getElementsByTagName('Elementvaluetobeupdated').item(0).textContent = 'updated value'


    message.body is having read/write permissions as per link - 
    https://www.ibm.com/docs/en/api-connect/5.0.x?topic=reference-api-connect-context-variables
    Has anyone came across such error ? Please advise.



    ------------------------------
    Many Thanks, Sunil
    ------------------------------


  • 2.  RE: NO_MODIFICATION_ALLOWED_ERR

    Posted Fri November 19, 2021 08:51 AM
    Hi @Sunil Hunashikatti- thanks for your question! I've asked around and an SME suggested the following:

    Can you try nodeValue instead of textContent ?
    I believe textContent is read only in situations where you are accessing an Element that has inner Elements.

    Hopefully that helps!

    ------------------------------
    Jina K
    ------------------------------



  • 3.  RE: NO_MODIFICATION_ALLOWED_ERR

    Posted Tue November 23, 2021 02:02 PM

    Unfortunately, the XML DOM implementation of GatewayScript did not include the write/update methods of the DOM API, only the read functions such as the getElementsByTagName and getElementsByTagNameNS that you reference in your post.  The JSON objects are also read only so textContent or nodeValue cannot be modified in the JSON object directly.  As an example, I tried using the GatewayScript debugger and I get the same exception:

    (debug) p test.item(0).nodeValue = "hello world"
    Error: DOM 'NO_MODIFICATION_ALLOWED_ERR' exception.
    (debug) p test.item(0).textContent = "hello world"
    Error: DOM 'NO_MODIFICATION_ALLOWED_ERR' exception.

    I would suggest you submit a request for enhancement for the create / write / update functions of the DOM API.   In the meantime, within GatewayScript itself, you only have a couple of options: 1) string functions, ie, XML.stringify the DOM, locate where in that string the value you wish to change and replace it and then XML.parse the string if you wish to have the DOM structure with the updated value, or 2) you could do a transform.xslt to call a xslt from the GatewayScript, passing the DOM and having parameters that would include your updated values where the xsl  could simply be an identity transformation that took the parameter value and updated the resultant element value.  Agreed not the most elegant solution without the create / write / update functions.  RFE's can be submitted on https://secure.aha.io/session/new?requested_domain=bigblue

    Regards,

    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------