HUDTo Code

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

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

HUDTo Code

Post by bandorganman »

Code: Select all

if (hb1.Hud109 > 0)
                        {
                            IOrderItem line109 = (IOrderItem)lines[109];
                            IList chgs = (IList)line109.GetProperty("Charges");
                            IOrderItem chg = (IOrderItem)chgs[0];
                            chg.SetProperty("Amount", hb1.Hud109);
                            chg.SetProperty("Description", hb1.Hud109A);
                            IOrderItem hto = (IOrderItem)chg.GetProperty("HUDTo");
                            hto.SetProperty("Code", order.GetProperty<IEnumerable<IOrderItem>>("Contacts").Single(t => t.GetProperty<ContactType>("ContactType") == ContactType.AllSellers));  // creates the below error
                             os.ApplyChanges(order);
                        }
Severity Code Description Project File Line
Error CS0308 The non-generic method 'IOrderItem.GetProperty(string)' cannot be used with type arguments SoftProConversion C:\dev\SoftProConversion\SoftProConversion\Form1.cs 4538

This is the code as you sent me in a previous post. How do I fix?
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: HUDTo Code

Post by BobRichards »

We actually have two issues...

If you want to set a contact to the value "AllBuyers" or "AllSellers", you have to get the collection from the order. You will never find one of these Contact types in the list of Contacts because it is always a collection - not an individual contact you created in the Add Contacts screen. Also, to assign a new contact to a HUD charge, you have to set the "HUDTo" property.

Code: Select all

...
IList chgs = (IList)line109.GetProperty("Charges");
IOrderItem chg = (IOrderItem)chgs[0];
chg.SetProperty("HUDTo", order.GetProperty("AllSellers"));
os.ApplyChanges(order);
The second issue is that I sent you incomplete code. I use helper methods in my code to make the code more intuitive to me and I forgot to remove the helper. If you want to set the "HUDTo" property to a contact in the order, you will have to remove the generic (GetProperty<IEnumerable<IOrderItem>>) and do it in multiple steps.

Code: Select all

var oContacts = (IEnumerable<IOrderItem>)order.GetProperty("Contacts");
IOrderItem oContact = oContacts.First(t => (ContactType)t.GetProperty("ContactType") == ContactType.TitleCompany);
hto.SetProperty("HUDTo", oContact);
Be aware that if the Contacts does not contain a Title Company (in this example), the First() method will throw an exception. If you are not sure if the type exists, use the LINQ Where() method and check for a null return before using the results.
Bob Richards, Senior Software Developer, SoftPro
bandorganman
Posts: 68
Joined: Tue Mar 03, 2020 5:23 pm

Re: HUDTo Code

Post by bandorganman »

Thanks, Bob! Happy New Year :)
Post Reply