I´m having a problem replacing a child value in my incoming xml.
I got the appending to work but now i have a doubble node in the xml.
Can somebody help me to change the append to replace (or remove existing node (DeliveryDate). The problem begins at "var = text2"
The script maybe a bit strange but i'm learning . every tip is welcome.
Thanks..
Code: Select all
// Is invoked each time a new job arrives in one of the input folders for the flow element.
// The newly arrived job is passed as the second parameter.
function jobArrived( s : Switch, job : Job )
{
var dataset = s.getPropertyValue('dataset', job);
var xpath = s.getPropertyValue('xpath', job);
var orderaantal = s.getPropertyValue('orderaantal');
var order2 = orderaantal * 1;
var order3 = (order2 - 1);
var reset = s.getPropertyValue('reset');
var num = 1;
var num2 = 0;
var databaseDataset = job.getDataset(dataset);
var theXMLDoc = new Document(databaseDataset.getPath());
var nodeByPath = theXMLDoc.evalToNodes("/Klantorders/Klantorder");
var theGlobalDataScope = "/be/gradual/www/" + s.getScriptName();
const theUniqueIDKey = "LabelWithUniqueID_UniqueID";
s.lockGlobalData( theGlobalDataScope );
var theUniqueID = s.getGlobalData( theGlobalDataScope, theUniqueIDKey );
var unid = theUniqueID;
var nummer = order3;
var totaal = "";
if (reset == "reset"){
theUniqueID = "0";}
else {
if (unid < order3) {
var theUniqueIDNumber = parseInt(theUniqueID) + 1;
theUniqueID = theUniqueIDNumber.toString();
nummer = num2.toString();
totaal = ((theUniqueID * 1) + (nummer * 1));
}
else if (unid == order3) {
nummer = (order2);
theUniqueID = num2.toString();
totaal = ((theUniqueID * 1) + (nummer * 1));
}
else {
theUniqueID = num.toString();
}
}
// Save the new Unique ID value
s.setGlobalData( theGlobalDataScope, theUniqueIDKey, theUniqueID );
// Don't forget to unlock global data again
s.unlockGlobalData();
var subt = (((order2 + 1) - totaal));
const mSInDay = 600000;
var milliSecsInDay = ((mSInDay * subt) + 518400000)
var tmwMilliSecs = new Date().getTime() + milliSecsInDay;
var tmw = new Date(tmwMilliSecs);
tmw.toString();
job.setPrivateData('tijd', tmw);
var text2 = theXMLDoc.createText(tmw);
var Node = theXMLDoc.createElement("DeliveryDate")
Node.appendChild(text2);
//replace all of node with new text
for(var i=0; i<nodeByPath.length; i++){
nodeByPath.at(i).appendChild(Node);
}
// Save the file
theXMLDoc.save(databaseDataset.getPath());
// And send the job to the next output
job.sendToSingle(job.getPath(), job.getName());
}
function timerFired( s : Switch )
{
}