Solved

Workflow Create Item is making multiple items

  • 12 December 2023
  • 7 replies
  • 76 views

Badge +2

SharePoint 2016

I have a workflow that collects data via for each loops, and at the end of the last loop it will create an item in a list and log that data. My issue is that it is making multiple items when it should only be making one. When the loops result in only having one entry to make it is fine, but if there are two items that need to be created, it is making four (two of each data sets). 

There are three levels of loops nested within each other, if that makes any impact. I made sure that collections remove duplicates. 

The Workflow

 

The duplicating items being created

EDIT: Here are clearer images of the workflow.

 

icon

Best answer by Garrett 15 December 2023, 05:14

View original

7 replies

Userlevel 1
Badge +8

Hard to see based upon image, but I would move the Create Item out of the innermost loop to the one below it (the next available insertion point)

 

 

Badge +2

Hard to see based upon image, but I would move the Create Item out of the innermost loop to the one below it (the next available insertion point)

 

 

I’ve tried that and the problem remains. Moving down to to the loop after then only grabs one of the Log# and makes 2 items of it.

Userlevel 6
Badge +16

Hi @mstallings 

Use Log to History action to debug your workflow. 
Disable the Create Item action.
After the Create Item action, add a Log to History action and display all important variable values

1 Log action before entering LOOP

1 Log action at the start of the LOOP

1 Log action inside the LOOP where the Item is created 

1 Log action at the end of the LOOP

1 Log action after exiting LOOP

 

Test with the following workflow scenario

  • Item is 0. No Looping (does not enter Loop)
    Outcome. Log for Before Enter and After Exit. No Item is created
  • Item is 1. Perform loop action once and exit. Outcome: 1 item is created
  • Item is 2. Perform loop action twice and exit. Outcome: 2 items is created
  • Item is 3 or more 

Trace the Log to identify where the additional create item is occurring. 

Badge +2

Hi @mstallings 

Use Log to History action to debug your workflow. 
Disable the Create Item action.
After the Create Item action, add a Log to History action and display all important variable values

1 Log action before entering LOOP

1 Log action at the start of the LOOP

1 Log action inside the LOOP where the Item is created 

1 Log action at the end of the LOOP

1 Log action after exiting LOOP

 

Test with the following workflow scenario

  • Item is 0. No Looping (does not enter Loop)
    Outcome. Log for Before Enter and After Exit. No Item is created
  • Item is 1. Perform loop action once and exit. Outcome: 1 item is created
  • Item is 2. Perform loop action twice and exit. Outcome: 2 items is created
  • Item is 3 or more 

Trace the Log to identify where the additional create item is occurring. 

 

I found that the workflow is running through the Activity# Loop twice, thus creating the item twice. Any ideas as to why that could be? It starts running twice when it is at “Item is 2.” per your example scenario.

Userlevel 6
Badge +16

Hi @mstallings 

The Create Item inside Loop 3 is the ISSUE. You are creating n * n records. 
If n is 1, 1 record is created. 
If n is 2. then 2 * 2 is created.

You need to move the Create Item action out of Loop 3

 

If you create 1 record per Employee, then place the create Item after you exit Loop 2
If you create 1 record per Employee-Activity, then place the create item after you exit Loop 3    

Badge +2

Hi @mstallings 

The Create Item inside Loop 3 is the ISSUE. You are creating n * n records. 
If n is 1, 1 record is created. 
If n is 2. then 2 * 2 is created.

You need to move the Create Item action out of Loop 3

 

If you create 1 record per Employee, then place the create Item after you exit Loop 2
If you create 1 record per Employee-Activity, then place the create item after you exit Loop 3    

I need one record for each Employee-Log-Activity.

When I put the create item after exiting Loop 3, it is still duplicating records.

When I put the create item after exiting Loop 2, it only creates a record for one Log & Activity and it is still duplicating that record.

Userlevel 6
Badge +16

Hi @mstallings 

If you need one record for each Employee-Log-Activity, then the Create Item should be in Loop 3.

One of the reasons may be that creates duplicate records is because incorrect variables or non-updated variables.
e.g. Loop is only reading the first record where the loop is not moving to the next record.
e.g. Loop is moving to the next record however it only uses the values from the first record when creating item(s).

 

I suggest you perform a PEER REVIEW where you get another set of eyes to review (and debug) your code.

Reply