Page 1 of 1
multiple XML nodes in email alert
Posted: Mon Feb 20, 2017 3:19 pm
by abonsey
Hi All,
I'm looking at taking the XML nodes (items ordered) and sending a email listing the items order.
How do I get the repeating XML data into an email.
Thanks for any help
Re: multiple XML nodes in email alert
Posted: Thu Mar 16, 2017 12:16 am
by abonsey
Hi All,
I'm still struggling with this. I can place metadata node based on:
/item[1]/value
/item[2]/value
etc
but i want to extract all items ie /item[???] and then list in an email
Is it possible??
Thanks for any help
Re: multiple XML nodes in email alert
Posted: Thu Mar 16, 2017 11:34 am
by sander
I heavily rely on PrivateData in my flows so I would create script and write every node that exist into a PrivateData key.
I do something similar over here:
Code: Select all
// OrderRowNumber, OrderRows, OrderRowsTotal is taken from a different query.
// Column1: OrderRowNumber
// Column2: OrderRow
// Column3: Bestand
for (i = 1; i < 21; i++) {
// OrderRow
var string = job.getVariableAsString("[Metadata.Text:Path=\"//Row["+i+"]/Column[2]\",Dataset=\"OrderRow\",Model=\"XML\"]");
if (string != null) { if (string.toLowerCase() == 'undefined') { string = '' ; }
job.setPrivateData('OrderRow'+i,string);
job.setPrivateData('OrderRowsTotal',i); // Haha!
}
With this I have OrderRow01-OrderRow20 in PrivateData. When no node is found the key simply doesn't exist.
Edit: And with this logic and with the magic of e.g. a script expression you can create a nice mail
Hope it helps,
Re: multiple XML nodes in email alert
Posted: Thu Mar 16, 2017 5:09 pm
by abonsey
Hi, Thanks for that it helps a lot.
Are you able to multiple privatedata in one hit ie instead of OrderRow01, OrderRow02, OrderRow03 by using a wildcard and a separator ie OrderRow[*] & ,
Re: multiple XML nodes in email alert
Posted: Thu Mar 16, 2017 8:33 pm
by freddyp
Instead of putting everything in different pieces of private data, just put everything into one string and put the separator that you need inside the string. For use in the To or CC fields that would be a semicolon, for use in lines in an HTML mail that would be <br>, ...
Codewise (not tested)
Code: Select all
var mails ="";
var itemValues = xmlStructureVariable.evalToNodes("//item[*]/value");
for (var i=0; i<itemValues.length; i++) {
mails = mails+itemValues.at(i).getFirstChild().getValue()+"<br>";
}
job.setPrivateDate("Mails",mails);
Re: multiple XML nodes in email alert
Posted: Fri Mar 24, 2017 11:26 am
by sander
Thanks Freddy!
I'm using your example for another case to push all files I gather from a xml into a flow. In this case, I do have a number of unknown nodes so your example is perfect.
Thanks,