Ambiguous Template Error

Discussions concerning general integration topics.

Moderator: Phil Barton

Post Reply
lukewautier
Posts: 7
Joined: Tue May 11, 2021 4:53 pm

Ambiguous Template Error

Post by lukewautier » Mon Jun 14, 2021 5:30 pm

When attempting to apply a template to a newly created order I am receiving the following error message:

Code: Select all

Exception Details: SoftPro.OrderTracking.Client.Lookups.AmbiguousLookupException: The ILookups.DisambiguateLookupRow event did not handle the situation where two lookups rows had the same key field and it was retrieved. at SoftPro.OrderTracking.Client.Lookups.ApplyLookupScope.LookupApplier.Retrieve(ITypeDescriptorContext context) at SoftPro.OrderTracking.Client.Lookups.ApplyLookupScope.LookupApplier.ExecuteInternal(ITypeDescriptorContext context) at SoftPro.OrderTracking.Client.Lookups.ApplyLookupScope.LookupApplier.Execute(EventHandler`1 disambiguateLookupRowGlobal, EventHandler`1 disambiguateLookupRowLocal, ITypeDescriptorContext context) at SoftPro.OrderTracking.Client.Lookups.ApplyLookupScope.ApplyInternal(ITypeDescriptorContext context) at SoftPro.OrderTracking.Client.Lookups.ApplyLookupScope.Apply(ITypeDescriptorContext context) at SoftPro.OrderTracking.Client.Orders.OrderBase`1.RootEntity_NestedPropertyChanged(Object sender, NestedPropertyChangedEventArgs e) at SoftPro.EntityModel.NestedPropertyChangedEventInstance.Fire() at SoftPro.EntityModel.EntityTransactionContext.<>c__DisplayClass26_0.b__0() at SoftPro.EntityModel.EntitySynchronizationContext.Invoke(Action action) at SoftPro.EntityModel.EntityTransactionContext.FireEvents() at SoftPro.EntityModel.EntityTransactionContext.Scope.Dispose() at SoftPro.OrderTracking.Client.Orders.OrderBase`1.SoftPro.OrderTracking.Client.Orders.IOrderPrivate.ApplyTemplate(IOrder source, OverlayAction action) at SoftPro.OrderTracking.Client.Orders.OrderBase`1.SoftPro.OrderTracking.Client.Orders.IOrder.ApplyTemplate(IOrder source)
I'm using the following code sample.

Code: Select all

static private IOrder CreateNewOrder(SelectServer ss, IOrderStore os, List<string> tName, string baseNumber, SettlementType myST)
        {
            //Create an order number, and specify a template to overlay, as well as another order to overlay
            OrderCreationSpec spec = new OrderCreationSpec();
            spec.BaseNumber = baseNumber;
            spec.SettlementType = myST;
            IOrder order = null;
            try
            {
                //set the specifications
                order = os.NewOrder(spec);
                //Save the order in the database.
                os.ApplyChanges(order);
            }
            catch (Exception ex)
            {
            }
            try
            {
                //apply the templates
                foreach (string lonetName in tName)
                {
                    List<IOrderInfo> search = os.Orders.Where(t => t.Number == lonetName).OrderBy(t => t.Number).ToList();
                    foreach (IOrderInfo mysearch in search)
                    {
                        using (IOrder template = os.OpenOrder(mysearch, OrderEditMode.ReadOnly))
                        {
                            order.ApplyTemplate(template);
                            os.ApplyChanges(order);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return order;
        }
       
I have verified that this template name is unique with no hidden duplicates. The odd thing is that the template seems to apply correctly as far as I can tell.

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

Re: Ambiguous Template Error

Post by BobRichards » Mon Jun 14, 2021 8:45 pm

The exception is not saying that the template name is ambiguous (necessarily) - but rather some piece of data being inserted into the new order creates an ambiguous lookup table scenario. Normally the Select application would handle this for you by presenting a dialog with your options to choose from.

If you are creating orders via API, then you need to handle the disambiguation routine yourself. If you examine the ILookups interface (SoftPro.OrderTracking.Client.Lookups) you will see the DisambiguateLookupRow event. Get the interface and subscribe to the event before you create an order. It is up to you to handle all events that occur to resolve the correct lookup table value among the ones with duplicate keys.

See the SoftPro Select SDK Documentation help file to see an example in the topic: How-To / Lookup Tables / Handling Disambiguities.
Bob Richards, Senior Software Developer, SoftPro

lukewautier
Posts: 7
Joined: Tue May 11, 2021 4:53 pm

Re: Ambiguous Template Error

Post by lukewautier » Tue Jun 15, 2021 4:28 pm

Thank you Bob, that pointed me in the right direction to address the issue.

Post Reply