0

I'm trying to figure out the logic behind this solution, and need some help. I've have an InfoPath form connected to one of my SP lists, and everything works fine. The problem is that now I want to include NEXT and PREVIOUS buttons on my form, where users can immediately go to the next or previous record in the list without having to exit the form and enter it again. I've played around with the rules, but can't seem to get the form to advance (or step back) to the next (or previous) record. Have any of you that use IP dealt with this? How did you fix it?

0

There is no command in InfoPath to do this.

It might--might--be possible with some really convoluted rules. InfoPath list item forms load new items by refreshing the main data connection. (It's possible that this is only for "Manage Multiple List Item" forms, I don't remember 100%). Have a rule set the query fields on the main data connection, then refresh, and the new items will be loaded.

So for a next button, set the ID in the main data connection query field to the ID of the next list item, then refresh the connection.

The trick of course will be figuring out the ID of the next and previous items. IDs start sequential, but when items are deleted it creates gaps. You also need to figure out if you are at the first or last item. You will have to do this via a data connection back to the list. However, deriving next and previous ids from a normal list data connection is going to be nearly impossible in xPath, so instead of creating a normal list data connection, create two data connections via REST API: one for previous ID, and one for next ID. For the next ID, filter the REST so that ID > current item ID, sort ascending by ID, and set a rowlimit of 1. First item to come back is the "next" item in the list, so your next button sets the main data connection query field ID to that, then refreshes. Will look something like this:

[%your website%]/_api/web/lists/getbytitle('your list name')/items?$filter=ID gt [%current item ID%]&$rowlimit=1&$orderby=ID asc

For the previous item, the opposite: filter to ID < current item ID, sort descending by ID, rowlimit 1. Whatever comes back is the previous item. Something like this:

[%your website%]/_api/web/lists/getbytitle('your list name')/items?$filter=ID lt [%current item ID%]&$rowlimit=1&$orderby=ID desc

There will obviously be a lot of fleshing out to do, but that is the broad outlines of the only solution I can think of.

  • Let's say, for the sake of argument, that they will never delete records (unrealistic, to be sure, but humor me). With this not being an issue, we can refer to 2 new fields I've created where calculations are made (ID+1 and ID-1). With these in place and functioning properly, the next problem is making the form display where ID = ID +1 (or -1) on click. I haven't been able to make the InfoPath rules make this part happen. This is where my question is. What am I missing in the Rules to make this take place? – DanJ Nov 7 '18 at 21:03
  • Set a Field's Value -> Field: Main Data Connection -> Query -> ID Value: ID +/- 1 Refresh Data Connection: Main Data Connection That might only work on a Manage Multiple List Items form, though. – Andrew Ridgway Nov 7 '18 at 21:34

Your Answer

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

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