Page 1 of 1

Recent Documents

Posted: Wed Dec 16, 2015 7:16 pm
by MattW
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() });
 }


Re: Recent Documents

Posted: Thu Dec 17, 2015 9:16 am
by Phil Barton
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.

Re: Recent Documents

Posted: Tue Dec 22, 2015 1:23 pm
by MattW
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?

Re: Recent Documents

Posted: Thu Jan 07, 2016 11:03 pm
by BobRichards
Do you mean that you get a different ordering if you run the same query multiple times? Do you have an example?

Re: Recent Documents

Posted: Tue May 31, 2016 3:12 pm
by MattW
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)?

Re: Recent Documents

Posted: Wed Jun 01, 2016 1:33 pm
by BobRichards
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.