Workflow action to query the list for items created by the current user and delete old items

  • 29 November 2023
  • 7 replies

Badge +3

I’m trying to create a query list action on a workflow that pulls back the IDs of all the items created by the initiator in order to delete the old items if they exist.

I’ve added the query list action, but when trying to pull all the item numbers into a collection variable, it doesn’t pull any numbers through at all.  The filter is searching the ‘user’ column on the list, with the ‘user’ being a variable that’s set previously as the initiator.

I’m using Nintex for SharePoint on-premis, after i’ve got the list of IDs that are created, I need to be able to delete the oldest one(s). so there’s only 1 item for each user.

Is anyone able to assist me, so that I can get this workflow working for the client.


Best answer by BobR 30 November 2023, 10:59

View original

7 replies

Userlevel 5
Badge +12

Is this a site or list workflow?

Have you tried inserting a reference variable to the Initiator instead of the “user” variable?

I would also suggest using a “Log in history list” action to write and compare the values returned for the User list column and the user variable.

Userlevel 6
Badge +21

Hi @DonnaA,

I was going to say what @bamaeric said.
Log your user variable and then query a user on the list, and then log that and compare.
One may be a First Name Last Name, and one may be an email address, etc, so they are different and will never match.

Badge +3

It’s a list workflow.

I’ve already done the output of what the user field shows and it matches what is in the Initiator, although I am using the ‘Contains’, rather than equals to

Userlevel 1
Badge +6

This depends on the format the Person or Group variable [user] is set in. I struggled with this as well. Try the following:

  • Make a set variable action to define a second Person variable (let’s call it UserID), and set it equal to Workflowdata variable [user], put this before the List Query action
  • In this set variable action, next to the line where you equal it to the [user] variable, there should be a button with three dots on it, click on that to select a return type
  • Pick user id-number from the options.
  • Use your List Query action to check the column against this new [UserID] variable instead of the [user] variable.
Badge +3

Thanks, That’s worked perfectly. Now i need to work out how to delete all the old items, and keep the current one, any ideas?

Userlevel 1
Badge +6

I think the easiest solution would be to instead of List Query use a “Delete multiple items” action. It uses the same filters as List Query, so you could pull up the old items in the same way. If you want to keep the current one, I’m assuming that’s the item the workflow is running on, you could add a second condition, like:

Condition 1: User equals [UserID]


Condition 2: Id does not equal [Id]

This excludes the current running item from being pulled out and deleted.


If the Delete multiple items action doesn’t work, (it has been buggy for me) you can also use a For Each loop after the List Query (and exclude the current ID through the List Query), then use a standard Delete item action by matching the ID to the one currently in the For Each loop.

Badge +3

Thanks, i’ll give that a try