Renaming js object tag when using load() | Community
Skip to main content
lukkyluke
New Participant
March 5, 2020
Solved

Renaming js object tag when using load()

  • March 5, 2020
  • 2 replies
  • 5825 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Milan_Vucetic

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

2 replies

lukkyluke
lukkylukeAuthor
New Participant
March 13, 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);

 

Milan_Vucetic
Milan_VuceticAccepted solution
New Participant
March 5, 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

lukkyluke
lukkylukeAuthor
New Participant
March 13, 2020

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. 🙂