Renaming js object tag when using load()

Avatar

Avatar

lukkyluke

Avatar

lukkyluke

lukkyluke

05-03-2020

Hi everyone,

I am trying to rename a js property (within the view object) and would like to replace the view-object with a new edited object, but I am struggling.

var offerToEdit = NLWS.nmsOffer.load(offer.@id); //loads the specified offer fine
offerToEdit.view = updatedViewObjectWithAnEditedPropertyName // does not work
delete offerToEdit.view //does not work
offerToEdit["view"] = "" //does not work
offerToEdit.view = 'test' //does not work
offerToEdit.view = '{"test":""}' //does not work
offerToEdit.view = '<view/>' //does not work
offerToEdit["view"] = '<view/>' //does not work
offerToEdit.view.shortContent_jst = 'New title'; //works fine

Is it only possible to edit the values of a property or am I doing something wrong here? Any workaround?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Milan_Vucetic

MVP

Avatar

Milan_Vucetic

MVP

Milan_Vucetic
MVP

05-03-2020

Hi @lukkyluke 

 

use this to remove old node:

 

var offerToEdit = NLWS.nmsOffer.load(offer.@id);

var offerToEdit = DOMDocument.fromXMLString(offerToEdit.toDocument().toXMLString());
var y = offerToEdit.getElementsByTagName("view")[0];
offerToEdit.documentElement.removeChild(y);
//logInfo(offerToEdit.toXMLString());

 

After that, just append new one.

 

Regards,

Milan

Answers (1)

Answers (1)

Avatar

Avatar

lukkyluke

Avatar

lukkyluke

lukkyluke

13-03-2020

Hi again, just wanted to give you an update on how I solved it.

var loadedOffer= NLWS.nmsOffer.load(offer.@id);
var offerToEdit = new DOMDocument.fromXMLString(loadedOffer.toDocument().toXMLString()); 
offerToEdit.renameNode(offerToEdit.getElementsByTagName("view")[0].getElementsByTagName("testTagBeforeRenaming")[0], "", "testTagAfterRenaming")

var sqlUpdateQuery = "UPDATE NMSOFFER SET MDATA=TO_NCLOB('" + offerToEdit.toXMLString().replace(/'/g, "''") + "') WHERE IOFFERID=" + offer.@id;
var result = sqlExec(sqlUpdateQuery);