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?
Solved! Go to Solution.
Views
Replies
Total Likes
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
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
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.
Views
Replies
Total Likes
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);
Views
Likes
Replies
Views
Likes
Replies