1

Is it possible to build a dictionary, and then perform an actual action (such as set field value) on every item in that dictionary?

The Objective - I have a list lets say"Test List" (for simplicity let's say it has 4 columns) and i am running the workflow on item 1

SharePointList

Now when Cost field is updated on item ID 1, the lookup cost will change for items ID 3 & 5, but the calculated fields in 3 & 5 will not update until the items are modified in some way.

Solution so far - So what i have done is Create a string variable "domain/site/_api/web/lists('test list')/items?$filter=Lookup on ID eq '([%CurrentItem:ID)'

to create my call to "domain/site/_api/web/lists('test list')/items?$filter=Lookup on ID eq '1'

which when i count returns 2 items. I build the dictionary with these 2 items

The Problem - Now I have seen many posts showing how you can iterate through that dictionary to get the values out of it, and then log them in a variable you can then use in to log to history or send an email. However i want to actually do something to those items in the dictionary such as set a 5th column "say date modified" to today in order to update the calculated field.

once my dictionary is built, is it possible to, for instance count my dictionary items (which will equal 2 in this case, this i have already achieved) to create my loop, then


First Loop 
Get next ID from dictionary > (3)
update column 5 with today's date(just for example doesn't have to be a date just something to make it update), in the item with ID (3)

Second Loop
Get next ID from dictionary > (5)
update column 5 with today's date in the item with ID (5)

I have also thought about doing this through update item in the loop, or If lookup ID = CurrentItem:ID but i have stumbled into problems there. I raised another question around using "IF" and "Update Item" as it is really a different question and it would be useful to learn if either method is possible and how to perform each method separately.

https://sharepoint.stackexchange.com/questions/187618/sharepoint-2013-workflow-update-all-items-with-value-using-if-or-update

Thanks in Advanced

1 Answer 1

1

Reading through my question, I realised I had already answered it, sort of.

So first thing you want to do is create a loop using call http web services, you can find lots of examples of how to do this. such as http://weblogs.asp.net/ricardoperes/looping-through-list-items-in-sharepoint-2013

so in my list lets just look at three columns

ID - LookupID - updated (in the image below, the field "Text3" is my updated column)

now in the first step you will want to add a filter when creating your url variable, that takes the ID of the item running the workflow and only finds items that have said ID in the LookupID column. example below

https: //domain/site/_api/web/lists/getbytitle('TESTLIST')/items?$filter=LOOKUPID eq '[%Current Item:ID%]' (remove the space between https: and //)

Then follow the instructions from the above site until you get to the section where you "Get Fields" inside the loop

enter image description here

I was stuck because I couldn't find a command to act on the items in the dictionary, but then I realised, I can create a variable to contain the ID (that will change each time the item loops) of each item the workflow loops through and immediately after I can then create an update action to look for the ID variable in my list and update a field.

As you can see I have two update fields (the second one sets Text3 to Second Update, for testing purposes) however I kept it as I wasn't sure if the update would actually update my item if it already contained that value.

A big thanks to all the stack exchange questions and answers that lead me along the path to this solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.