Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Renaming js object tag when using load()

lukkyluke
Level 3
Level 3

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?

1 Accepted Solution
Milan_Vucetic
Correct answer by
Community Advisor
Community Advisor

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

View solution in original post

3 Replies
Milan_Vucetic
Correct answer by
Community Advisor
Community Advisor

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

View solution in original post

lukkyluke
Level 3
Level 3

Hi Milan and thanks for your suggestion! However, I will not be able to use the save function after converting to a DOMDocument, right? Do you got any nice solution for this as well?

 

Edit: I found ot I could do a sqlExec update on nmsOffer MDATA. 🙂

lukkyluke
Level 3
Level 3

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);