I have a Web API call that will assign one account to one Active Directory group. These requests come in bulk, e.g. add 3 groups to 15 accounts. The request is an Incident object and the groups and accounts are each linked via one-to-many relationships.
So I want to iterate over all pairs (account, group) and issue the Web API call for each pair. However, I can't figure out a way to do this in a one-step.
The Step-Through-Children action allows me to iterate over one relationship but not both - I can nest another Step-Through-Children action, but the context has changed to the child object.
You can do this by stepping through each item in one relationship, and manually serializing the data into an XML collection, in a variable or stored value of data type XML Collection.
Then, step through your next relationship, and once inside, Step Through The XML collection using a Step Through Collection action.
You'll want your collection to look something like this:
If you're new to collections... Don't change that 'Item' tag to be 'Item2', 'Item3', etc. You need the items in the list to have the same tag, with field values inside.
The StepThroughCollection action, when pointed to this variable, will step through each 'Item' element in the RelatedItem_List , and places the current <Item> into a variable for you.
You can then execute an action using data from the current item in your Step Through Children action, As Well As data from the current item in the Step Through Collection action, and you can filter the field values out of your current item using the modifier "String From Element" and passing it the name (without brackets) of the element you placed that value in (Field1, Field2, etc above).
Think about how you want to limit this, so you don't end up running the command more than once per matching AD group / person; such as executing an action in your nested Step Through Collection action to send the API call only when it matches the right AD group.
Works great, thanks!
For anyone building a similar one-step, maybe my example will help you... My one-step is structured as below. Sub-points (2a, 4a, 4a1) are nested under the step-through actions. Square-bracket [values] indicate field values rather than literal text.
1) Update a Variable - Initialize the variable AccountsXML to "<RelatedItem_List>" and set data type to "XML Collection"
2) Step Through Children - Iterate over the Account relationship
2a) Update a Variable - Append an account name by setting AccountsXML value to "[AccountsXML]<Item><Name>[Account.Full Name]</Name></Item>"
3) Update a Variable - Finish building the XML collection by setting AccountsXML value to "[AccountsXML]</RelatedItem_List>"
4) Step Through Collection - Iterate over the AccountsXML collection. Current item stored as CurrentAccount.
4a) Step Through Children - Iterate over the Group relationship
4a1) WebAPI call - Issue the web API call. The field Group.Name is directly accessible. The CurrentAccount variable needs the modifier "String from Element" with the Element set to "Name", which retrieves the stored value of [Account.Full Name].
Somewhat relevant - Video I created back in April 2017 on how to serialize a related item's data into an XML collection for use at the parent level. In this case, Ryan is going a step further and using that inside of a step through collection action taken after the data has been serialized.
www.youtube.com/watch - For maximum value, play at 2x speed. I talk pretty slow in this one.