0

first post here. I'm a frequent visitor to the site but haven't posted until now. Now I'm facing an issue that has almost beaten me and I need your help.

My scenario (using SharePoint Designer and SharePoint Online):

I have a list that I need to retrieve item info from using a SharePoint 2013 workflow and calling the SharePoint REST api to then create an email summary if you like of the last 5 items created.

My issue is that when I set an index variable to 0 and then make sure the loop includes a calculation of index plus 1 to increment, it counts up just fine and logs to the history list as expected but what I need is for it to start from the highest item result number (using a count of items variable) and inserting a calculation of count minus 1 which I then output to a calculation result variable and set that to my item result number in my get action to then count down the last 5 items created. I set this up and no results log to the history list. I'm calling from _api/web/lists/getbytitle('listname')/items.

Also there aren't many clear articles on sending the summary email. When I insert a result variable in to a send email action it only returns the last item in the loop but returns all items to the history list using the index plus 1 method.

Apologies if this is really long winded but trying to as specific as possible.

I'd appreciate any help I can get and will post screenshots if needed.

SharePoint Workflow

  • please post the screenshot it is always helpful – SharePointer Jun 28 '17 at 19:04
  • updated post (yeh i suck at image links) – user68258 Jun 28 '17 at 19:16
0

You can do following steps in your workflow

enter image description here

Basically, you start the index from the length of items and minus the 1 every loop and read the items from last to first.

Also, you can change the API query to include the order by clause and go with forwarding loop.

Example:

_api/web/lists/getbytitle('listname')/items/$orderby=Id desc

In the above query use your own order by field.

I hope this helps you to proceed further and let me know if I miss anything here.

  • Ok I will change it up and give this a go when I get a minute. I posted my workflow in my first comment if that helps. Thank you and I'll let you know how I get on./ – user68258 Jun 28 '17 at 19:17
  • You can follow the above logic. – Venkat Konjeti Jun 28 '17 at 19:20
  • Am I right in thinking I repeat the whole stage for each number of items I'd like in an email? – user68258 Jun 28 '17 at 19:28
  • You just need to loop through items, not the stage. In the stage you can add a Loop and condition is a loop until index equals 0. Do calculation before reading an item because index always length-1. – Venkat Konjeti Jun 28 '17 at 19:32
  • Mark as an answer if it solves your issue to help others to refer. – Venkat Konjeti Jun 28 '17 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy