Order Contacts

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
bandorganman
Posts: 68
Joined: Tue Mar 03, 2020 5:23 pm

Order Contacts

Post by bandorganman »

I get the following error:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Order' does not contain a definition for 'GetProperty'
at CallSite.Target(Closure , CallSite , Object , String )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at SoftProConversion.Form1.CreateOrder() in C:\dev\SoftProConversion\SoftProConversion\Form1.cs:line 3988

when executing the following code:

Code: Select all

 IOrderStore os = ss.GetService<IOrderStore>();
                        IOrder order = os.NewOrder(spec);
                        dynamic o = (dynamic)order;
                        o.Project = "RAL Test";
                        //o.ReceivedDate = ms.DATEOPEN;
                        
                        NEWMAST nms = getNewmast(ms.LINKNO);

                        o.SalesContract.SalesPrice = nms.SALESPRICE;
                        //Int32[] spDat = getSoftProDate(nms.DistributionDate);
                        //o.DisbursementDate = dt(spDat[0], spDat[1], spDat[2]);

                        //Contacts*************************************************************************************************************

                        HudBor1 hb1 = getHudBor1(ms.LINKNO);
                        HudBor2 hb2 = getHudBor2(ms.LINKNO);
                        HudSel1 hs1 = getHudSel1(ms.LINKNO);
                        HudSel2 hs2 = getHudSel2(ms.LINKNO);
                        Buyers buy = getBuyers(ms.LINKNO);
                        Sellers sel = getSellers(ms.LINKNO);
                        TITLEINS ti = getTitleins(ms.LINKNO);

                        IList contacts = (IList)o.GetProperty("Contacts");
What am I doing wrong?
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Order Contacts

Post by BobRichards »

Not really sure. Possibly because the Dynamic Language Runtime (DLR) can't determine that the object you passed to it can also be an IOrder object. Dynamic types can be fickle with complex types that implement multiple interfaces. When using interface methods (IOrder.GetProperty(), IOrderItem.SetProperty()), use the original explicitly typed object.

Code: Select all

IOrder order = os.NewOrder(spec);
...
IList contacts = (IList)order.GetProperty("Contacts");
Or explicitly cast the dynamic back to the required type.

Code: Select all

dynamic o = (dynamic)order;
...
IList contacts = (IList)((IOrder)o).GetProperty("Contacts");
Dynamic types are handy but can create difficult to understand rules about why it works sometimes and not others. I have stopped using them for production code. I just don't need to complicate my life with the strange errors that can pop up.
Bob Richards, Senior Software Developer, SoftPro
bandorganman
Posts: 68
Joined: Tue Mar 03, 2020 5:23 pm

Re: Order Contacts

Post by bandorganman »

Thanks for that explanation! Big help!
bandorganman
Posts: 68
Joined: Tue Mar 03, 2020 5:23 pm

Re: Order Contacts

Post by bandorganman »

Another problem is with entering address information to a contact. Name goes in fine but when I try to set Address1 I get an error.

Code: Select all

IList contacts = (IList)((IOrder)o).GetProperty("Contacts");

                        IOrderItem newAtty = ((IOrder)o).CreateNew("Attorney");
                        contacts.Add(newAtty);
                        newAtty.SetProperty("Name", ms.ATTYNAME);

                        IOrderItem newSbrok = ((IOrder)o).CreateNew("SellingAgentBroker");
                        contacts.Add(newSbrok);
                        newSbrok.SetProperty("Name", nms.SBROKER);
                        newSbrok.SetProperty("Address1", nms.SSTREET); // This causes an error
                        newSbrok.SetProperty("City", nms.SCITY);
                        newSbrok.SetProperty("State", nms.SSTATE);
                        newSbrok.SetProperty("Zip", nms.SZIP);
                        newSbrok.SetProperty("Phone", nms.SPHONE);
                        newSbrok.SetProperty("Fax", nms.SFAX);
                        newSbrok.SetProperty("MainPerson.FullName", nms.SBROKagent);
How do I enter the address info?
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Order Contacts

Post by BobRichards »

The contacts do not have an "Address1" property. Look at the Field Code Browser (FCB) for any contact and you will see that contacts have an "Address" object property. Get that property then set fields on it. Buyers and Sellers are a little different so check the FCB for the available address properties.

Code: Select all

IOrderItem newSbrok = ((IOrder)o).CreateNew("SellingAgentBroker");
contacts.Add(newSbrok);
newSbrok.SetProperty("Name", nms.SBROKER);

IOrderItem addr = (IOrderItem)newSbrok.GetProperty("Address");
addr.SetProperty("Address1", nms.SSTREET); // This causes an error
addr.SetProperty("City", nms.SCITY);
...
Bob Richards, Senior Software Developer, SoftPro
bandorganman
Posts: 68
Joined: Tue Mar 03, 2020 5:23 pm

Re: Order Contacts

Post by bandorganman »

Thanks! That clears a lot of things up!
Post Reply