DataPower

 View Only
  • 1.  NO_MODIFICATION_ALLOWED_ERR

    Posted Tue October 26, 2021 06:03 PM
    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 Wed October 27, 2021 07:51 AM
    Did you parse the body using a parse action first? By default the message body is not parsed I believe.

    ------------------------------
    Charlie Sumner
    ------------------------------



  • 3.  RE: NO_MODIFICATION_ALLOWED_ERR

    Posted Wed October 27, 2021 04:17 PM
    Edited by Sunil Hunashikatti Wed October 27, 2021 04:18 PM
    I checked the type for "xml" - it's nodelist. I assume it is parsed. 
    I did try same, implementing in javascript and it produces correct output with updated value for specified element in resulting xml.

    I'm not able to find the concrete reason yet. I believe "message.body" can be altered and is not read only.

    Finally, i tried to implement with XSLT and achieved the desired outcome.

    ------------------------------
    Sunil 
    ------------------------------



  • 4.  RE: NO_MODIFICATION_ALLOWED_ERR

    Posted Thu October 28, 2021 08:27 AM
    Edited by Steve Linn Thu October 28, 2021 08:47 AM

    Hi Sunil,

    Unfortunately, only the get functions for the XML DOM API are implemented.  You cannot update the XML DOM by an assignment as you are attempting or by using a DOM API update function such as replaceWholeText as it appears you are attempting to update the text node.  That particular property textContent is not only for current element but I believe it also includes the text content of its children, somewhat of an xsl:value-of type of value. For now the update of XML is best left to using xslt.  You could use a transform.xslt function to pass the DOM and the desired update value to the XSLT, let it do an identity transformation to update the text you desire, and then return the resulting DOM back to the GatewayScript.  I'd suggest you submit a request for enhancement for the addition of the update functions of the DOM API in GatewayScript.

    Best Regards,

    Steve



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