multiple XML nodes in email alert

Post Reply
abonsey
Member
Posts: 142
Joined: Fri May 24, 2013 5:10 pm

multiple XML nodes in email alert

Post 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
abonsey
Member
Posts: 142
Joined: Fri May 24, 2013 5:10 pm

Re: multiple XML nodes in email alert

Post 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
sander
Advanced member
Posts: 276
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: multiple XML nodes in email alert

Post 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,
abonsey
Member
Posts: 142
Joined: Fri May 24, 2013 5:10 pm

Re: multiple XML nodes in email alert

Post 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[*] & ,
freddyp
Advanced member
Posts: 1023
Joined: Thu Feb 09, 2012 3:53 pm

Re: multiple XML nodes in email alert

Post 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);
sander
Advanced member
Posts: 276
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: multiple XML nodes in email alert

Post 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,
Post Reply