Lookups by profile

Discussions related to custom development with Select.
Post Reply
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Lookups by profile

Post by ckootg »

Previously, I used the method GetService<Lookups>.FindTablesByKeyAndProfile to find the lookup table for the user's profile. Is the same method in Cameron or do we need to do it differently?
Graham Campbell
Posts: 61
Joined: Fri Jul 01, 2011 10:06 am
Location: Raleigh, North Carolina
Contact:

Re: Lookups by profile

Post by Graham Campbell »

In Cameron you will see that the Lookups class is no longer exposed and that you will need to interact with the ILookups interface instead. This interface should act the same as the class did previously.

You actually have another way to get the table in the current release which should be a lighter-weight action than the method you are currently calling. The method you are invoking is used in our code base for a single very specific UI pattern in the management console. This pattern has changed in Cameron and the FindTablesByKeyAndProfile method will no longer be supported. The advantage to using this other method is that you will leverage a cached set of results behind the API rather than make a call to the server every time that you invoke your request.


The preferred way to get a lookup table for a profile is through the ILookupMap interface. In the existing system you get to this through GetService<Lookups>().LookupMap. This class automatically uses the active profile for the user and provides ILookupMapEntry records detailing the lookup table for specified context/field pairs.

These interfaces have not changed significantly in Cameron, however there has been a change in pattern around profile usage. The lookups are now no longer relatively to the active profile, instead being relative to the order's owning profile. As such, we now need the consumer to specify the profile that they wish to have a ILookupMap for. As such, the new signature is GetService<ILookups>().GetLookupMap(profile).

Also, today the ILookupMap uses string representations of Context while in Cameron we use Types.

Here is some example Cameron code where we use these patterns:

Code: Select all

            // get services
            SelectServer sps = GetService<SelectServer>();
            ILookups lookups = sps.GetService<ILookups>();
            IProfileManager profileManager = sps.GetService<IProfileManager>();

            // get contextual information
            string path = ".LookupCode";
            Type contextType = endorsement.GetType();

            // get the lookup map by profile
            IProfileInfo profile = (IProfileInfo)order["OwnershipProfile"];
            ILookupMap map = lookups.GetLookupMap(profile);

            // check if we have a lookup table
            if (map.Contains(contextType, path))
            {
                ILookupMapEntry mapEntry = map[contextType, path];

                //get the table's schema
                LookupQuerySpec spec = new LookupQuerySpec()
                {
                    ID = mapEntry.ID,
                    SchemaOnly = true,
                };

                ILookupTable table = lookups.QueryTable(spec);
Please let me know if this information is inadequate or if you have any questions and I can try to give more details.
Graham Campbell
SoftPro Software Engineer
Graham Campbell
Posts: 61
Joined: Fri Jul 01, 2011 10:06 am
Location: Raleigh, North Carolina
Contact:

Re: Lookups by profile

Post by Graham Campbell »

There is a method which replaces the specific method that you were calling as well. If you do not want to interact with the cache of results and need to execute against the current data on the server then try this:

Code: Select all

            SelectServer sps = GetService<SelectServer>();
            ILookups lookups = sps.GetService<ILookups>();

            IProfileInfo profile = (IProfileInfo)order["OwnershipProfile"];

            List<ILookupTableInfo> tables = lookups.Tables
                .Where(t => 
                    t.OverlayContext == "Endorsement" && 
                    t.OverlayPath == ".LookupCode" && 
                    t.IsActive)
                .HavingProfile(profile)
                .ToList();
The ILookupTableInfo now supports the IHaveProfiles interface. This provides a series of extension methods which will allow you to filter the list of lookup tables comig back from the server. You will need to #include the right namspaces to see these extension methods. The HavingProfile extension method is in the SoftPro.Select.Client.Profiles namespace.
Graham Campbell
SoftPro Software Engineer
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: Lookups by profile

Post by ckootg »

That's exactly what I was looking for. Thanks Graham!
Post Reply