How can I send the output of a list query action in a single email?


Badge +3

I have successfully configured a Query List action to filter a list based on certain criteria. If I use the "Run Now" function within the action is displays the information correctly. In my case they are Assigned to and Title. I have these outputted to single line of text variables. I then have a Build string action which uses said variables and creates another single variable which I interest to an email. The issue is I get individual email notifications for all of the items on the list (112) rather than the 3 I want.

Side note, upon logging information to history throughout the process it would seem that it logs the filtered assigned to group on items that are assigned to different groups. IE - I want to only see tasks assigned to A however within the workflow of a task assigned to B it says within the log in history task that the assigned to person is in fact A which it isn't.


18 replies

Userlevel 5
Badge +14

I have these outputted to single line of text variables

you should save returned result set into collection variables. with single line text ones you will get saved just first item out of whole result set.

having it saved it collection variables you will have to setup for each loop over one of collection variables.

within the loop you will have to process single collection elements and prepare mail body.

finally, after the loop send notification with prepared content

have a look on these threads which deal with similar topic

Configuring a Workflow to send an alert when days have elapsed 

 

Badge +3

I tried to add the for each loop etc however now the workflow just hangs and doesn't complete at all. I have included screen captures below.

Userlevel 5
Badge +14

from a quick look I see following (possible) problems

- in query list action you ask to return a list field which's name is stored in "WorkflowLink" list field. is that really correct?

- in collection operation you reference 'Index' variable which is not initialized/populated. you have to populate value 'Index' variable with for each loop action

Badge +3

You're right with the "WorkflowLink" list field. I went ahead and removed that yesterday. Regarding the Index variable, is there specific information it should be populated by? What type of variable it should be? I tried making it a number variable and then assigning the item ID to it however that didn't seem to work out well...

Userlevel 5
Badge +14

it should be numeric variable.

do not assign a value to it on your own, for each loop action will take care of incrementing it with every loop iteration.

check documentation for further details

for each - https://help.nintex.com/en-US/nintex2013/help/#Workflow/RootCategory/Actions/Nintex.Workflow.ForEach.htm%3FTocPath%3DWor… 

collection operation - https://help.nintex.com/en-US/nintex2013/help/#Workflow/RootCategory/Actions/Nintex.Workflow.CollectionOperation.htm%3FT… 

Badge +3

Thanks for the links to the documentation regarding those actions. I understand what information should be used however I still can't get it to work in the way I want it to past the query list. The Query list action works correctly and outputs the filtered results I want. It doesn't matter which variables I use in the For each/collection operation I still get emailed 112 spate emails rather than one email containing the filtered result of the query list. Grrrr

Userlevel 5
Badge +14

send notification action has to be after the loop, not within the loop wink.png

within the loop just prepare mail body into a text variable. then send content of the variable in notification after the loop once all the data are collected.

Badge +3

Roger that. So I tried that and still got spammed however through further research it would seem that I would need to create collection operation tasks per item I would like to record? Now however the workflow starts and would seem to hang...I can't figure out why...However I feel I am moving forward.

{Breakdown of workflow}

Query list (Just above for each) - AssignedTo = Assign to collection variable, Title = Title Collection variable.

Foreach - title Collection variable is sent to a title text variable.

Get assigned to -  Assigned to Collection variable is sent to a Assigned to text variable.
Get related content - Related content Collection variable is sent to a Related content to text variable.

Build String -

{WorkflowVariable:EmailStringVar}


{WorkflowVariable:TitleVar}
{WorkflowVariable:AssingedToVar}
{WorkflowVariable:RelatedContentTextVar}

Userlevel 5
Badge +14

what action does workflow hang on?

do you already correctly work with index variable(s).

you don't seem/mention to populate any RelatedContent collection.

Badge +3

It no longer hangs, as you said I mentioned RelatedContent and didn't actually configure that variable. Now it works in the sense of it emails me with the information I want from the variables. However it sends the same correct information 112 times instead of once. It is working better than before. Haha.

Regarding the index variable the config for that was done at the "For Each Action". I linked the variable to a number.

Index config

Userlevel 5
Badge +14

I guess after previous exercise you have already moved sent notification action out of the loop...

then it looks like you have listed yourself 112 times in a notification addressee list (collection?) and you have configured the action to send individual emails.

so either clean the addressee list and remove duplicates or switch off sending individual emails.

Badge +3

Yep, the email notification action was moved out o f the loop.

I am only listed once within the email notification and I de-selected the option to send individually. I have deleted the notification action and re-added it however it doesn't make any difference. It is quite the mystery! I can't think of anything that would be causing this at this point.

Userlevel 5
Badge +14

don't you have any outer loop in workflow that may execute these set of actions repeatedly?

need not be right a loop action itself, might be as well a state machine if you go down the same branch several times.

are you sure (all the) notifications caome from the actual/latest workflow instance. can't they be sent by a previous instance(s)?

how do you start the workflow?

is it list or site workflow?

Badge +3

Nope, no outer loop now. I have included an image of the full workflow so you can see it in its entirety after the various changes.


Based on the amount of the emails they are coming from the workflow I run at that moment in time. I always receive 112 in a short period of time. I don't think that they are overlapping and in any case in order to receive that many emails I would have had to run the workflow around 40 times if it only ever sent out 3 emails each time.

I start the workflow via a PowerShell command. This is a list workflow connected to a workflow task list.

 

Userlevel 5
Badge +14

I start the workflow via a PowerShell command

don't you start it by any chance on each item in the list?

(or at least on some 112 items?)

Badge +3

Nope, I can't do that in this situation. The goal is to supply a weekly report so triggering this via a added item wouldn't really work. I plan to run the PowerShell command via a scheduled task every week.

Userlevel 5
Badge +14

could you share the ps script?

I have a bad feeling that it, maybe unintentionally, runs for each list item.

if you want to schedule workflow, you should have created a site workflow. you wouldn't need a ps script at all.

Badge +3

You were right. I didn't even think about the script being the problem! I created  a site workflow in my live environment and test that. It seemed to have worked as it should to an extent. The information within the email wasn't generated however I can work on that.

Here was he code I was using to start the workflow. I would run on each item causing that problem gahhhhhhhhh! Thank you for all of your help.

$web = Get-SPWeb -Identity http://sharepoint/siteurl

$manager = $web.Site.WorkFlowManager

$list = $web.Lists["Task listn ame"]

$assoc = $list.WorkflowAssociations.GetAssociationByName("Outstanding Decom Tasks","en-US")

$data = $assoc.AssociationData

$items = $list.Items

foreach($item in $items)

{$wf = $manager.StartWorkFlow($item,$assoc,$data,$true)}

$manager.Dispose()
$web.Dispose()

Reply