Recent Documents

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
MattW
Posts: 46
Joined: Tue May 26, 2015 5:17 pm

Recent Documents

Post by MattW » Wed Dec 16, 2015 7:16 pm

We have created a custom start page as a winform and are trying to recreate the Recent Documents feature from the default page. It successfully pulls orders in, but they are not consistently in the correct order. Most commonly listing the most recently opened order as the 2nd item rather than the first. What is the correct approach to always get the list of recently opened orders in the correct order?

This is what we are currently doing

Code: Select all


private void FillRecentDocuments()
{
      var envICE = _spServer.GetService<IEnvICE>();
      RecentDocuments_radGridView.DataSource = envICE.GetRecentOrders()
             .OrderByDescending(x => x.LastAccess).Take(6)
             .Select(x => new { OrderNumber = x.Title, OrderId = x.OrderId() });
 }


Phil Barton
Posts: 54
Joined: Wed Sep 24, 2008 2:37 pm
Location: Raleigh, NC
Contact:

Re: Recent Documents

Post by Phil Barton » Thu Dec 17, 2015 9:16 am

For the functionality that you're trying to implement, I would suggest using the IEnvICE.RecentDocuments property. It should return the collection of the recent documents sorted from most recent to least recent.
Phil Barton
Software Architect
SoftPro

MattW
Posts: 46
Joined: Tue May 26, 2015 5:17 pm

Re: Recent Documents

Post by MattW » Tue Dec 22, 2015 1:23 pm

I apologize I did not inlcude the entire code in my original post, we are currently using the RecentDocuments and receiving this behavior.

Code: Select all

private void FillRecentDocuments()
        {
            try
            {
                var envICE = _spServer.GetService<IEnvICE>();
                RecentDocuments_radGridView.DataSource = envICE.GetRecentOrders()
                    .Select(x => new { OrderNumber = x.Title, OrderId = x.OrderId() });
            }
            catch (Exception ex)
            {
                ex.WriteLog();
                ex.Show();
            }
            
        }

public static IEnumerable<IRecentDocument> GetRecentOrders(this IEnvICE envIce, int maxOrders = 6)
        {
            var rdc = envIce.RecentDocuments;
            var recentDocuments = rdc.Cast<IRecentDocument>().ToList();

            recentDocuments = recentDocuments.OrderByDescending(x => DateTime.Parse(x.LastAccess)).ToList();

            return recentDocuments.Where(x => x.IsOrder()).Take(maxOrders);
        }
You'll see the 2nd method GetRecentOrders() is the one that does the work of getting the RecentDocuments. I found however this doesn't give me only Order Documents so I do some checking that it is actually an order in the IsOrder() method by checking that the URI contains an orderId. Then sorting by the last access date. But as mentioned this does not reliably order the results.

Any Suggestions?

BobRichards
Posts: 906
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Recent Documents

Post by BobRichards » Thu Jan 07, 2016 11:03 pm

Do you mean that you get a different ordering if you run the same query multiple times? Do you have an example?
Bob Richards, Software Developer, SoftPro

MattW
Posts: 46
Joined: Tue May 26, 2015 5:17 pm

Re: Recent Documents

Post by MattW » Tue May 31, 2016 3:12 pm

This issue seems to have resolved itself at this time.

But to piggy back on this post:
Using the same code as posted above, it appears that templates do not show up in list returned from envIce.RecentDocuments.

Is there any way to get templates to show up in recent documents results (or another approach to retrieve them)?

BobRichards
Posts: 906
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Recent Documents

Post by BobRichards » Wed Jun 01, 2016 1:33 pm

I looked at the source code and it appears that you are getting the same list whether you log in with IEnvICE or with the Select client. The list is kept in a user AppData folder on the machine the client code runs. Perhaps you are logging in with different IDs or the same user ID but different machines? In either case, don't depend on the MRU list contents. It is a convenience feature and should not be depended on for critical production code.
Bob Richards, Software Developer, SoftPro

Post Reply