Problems setting County on a property

Discussions related to custom development with Select.
PeterKelly
Posts: 92
Joined: Tue Feb 04, 2014 3:34 pm

Problems setting County on a property

Post by PeterKelly »

When I manually set the County on a property using the lookup window in the UI it sets the following:

State
CountyGLC - Read only in UI
County
CountyTitle


Not knowing how to officially do this via the API I tried the following:

order.Properties[0].County = "Orange";

IEnumManager enumManager = userObject.sps.GetService<IEnumManager>();
var county_titles = enumManager.GetEnum<ICountyTitle>();
ICountyTitle county_title = county_titles.Values.Where(s => s.Description == "County").FirstOrDefault();
order.Properties[0].CountyTitle = county_title;

var states = enumManager.GetEnum<IState>();
IState california = states.Values.Where(s => s.Code == "CA").FirstOrDefault();
order.Properties[0].Address.State = california;


order.Properties[0].CountyGLC = "059";

As expected, when I try to set the CountyGLC I get: "Cannot access member."

What is the correct way to set the County and the other associated fields via the API?

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

Re: Problems setting County on a property

Post by BobRichards »

Assuming the County Lookup Table is available in the API user's profile, you only have to set the county attribute to a value in the table. Select fills in the remaining properties from the table for you.

Code: Select all

using (IOrder iOrder = os.OpenOrder(search))
{
	dynamic order = iOrder;
	dynamic property = order.Properties[0];
	property.County = "Wake";
}
Bob Richards, Senior Software Developer, SoftPro
PeterKelly
Posts: 92
Joined: Tue Feb 04, 2014 3:34 pm

Re: Problems setting County on a property

Post by PeterKelly »

What if there is more than 1 Wake county?

Also, the following code was added to the beginning of our script when first using the API to resolve some issues we were having with zip codes. I assume that disables the code you are suggesting? If so, is there a workaround?

ILookups lookups = sps.GetService<ILookups>();
lookups.DisambiguateLookupRow += (object obj, LookupRowSelectionEventArgs e) =>
{
e.SelectRow(e.LookupTable.Rows.First());
};

Thanks,
Peter
PeterKelly
Posts: 92
Joined: Tue Feb 04, 2014 3:34 pm

Re: Problems setting County on a property

Post by PeterKelly »

Actually that code should force it to select the first entry if there are multiple items, right?

Should the code I have below work? Isn't that equivalent to what you are suggesting?

order.Properties[0].County = "Orange";
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Problems setting County on a property

Post by BobRichards »

So your problem is that you are setting the property address County property in an API application with a key value that is duplicated in the County lookup table and you are not seeing a call by Select into your lookup row disambiguation event handler.

So assuming:
  • You are in a profile that the County lookup table is enabled for
  • There are multiple identical County column entries
  • You are not suppressing the lookup logic with a LookupSuppressionBlock
then perhaps the County field is already set to your value via template or if order previously existed. If you change the County from "Orange" (current order setting) to "Orange" (via API or UI), Select will see that the field didn't change and will not need to perform a table lookup.
Bob Richards, Senior Software Developer, SoftPro
PeterKelly
Posts: 92
Joined: Tue Feb 04, 2014 3:34 pm

Re: Problems setting County on a property

Post by PeterKelly »

The UI uses the same template for the same user and it shows the County field as blank.

Also, when we were looking at it together we tried "Del Norte" for the county and got the same results.

I have a workaround for now which is just setting the Zip Code of the County but this issue may show up again at a later time.

Thanks,
Peter
ddudley3
Posts: 55
Joined: Fri May 03, 2013 9:11 am

Re: Problems setting County on a property

Post by ddudley3 »

I'm trying to do this with Select client 4.1

and I'm getting this error

Cannot apply indexing with [] to an expression of type 'Property'

code is

dynamic props = order["Properties"];
dynamic property = props[0];
property["County"] = "Wake";
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Problems setting County on a property

Post by BobRichards »

The error message (Cannot apply indexing with [] to an expression of type 'Property') means that the Property object does not have a indexer method. Since it is a dynamic type at this point, you can do either of the two methods:

Code: Select all

// Dynamic property.
property.County = "Wake";

// Static indexer.
((IOrderItem)property)["County"] = "Wake";
While at first glance it looks like it should work because that's how you got the order properties, it is very different. The IOrderItem (and IOrder) interfaces have an indexer method. So when you get the properties initially, you are calling the indexer on an IOrderItem - not on the Select order model Order object.

Code: Select all

dynamic props = order["Properties"];	// GOOD: IOrderItem "order" supports indexers.
dynamic property = props[0]; 
property["County"] = "Wake";			// SYNTAX ERROR: Select Property object does NOT support indexers.
Bob Richards, Senior Software Developer, SoftPro
ddudley3
Posts: 55
Joined: Fri May 03, 2013 9:11 am

Re: Problems setting County on a property

Post by ddudley3 »

ok great.

What about sub structures though..

i.e. I need to set Line1 and City of Address under Property
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Problems setting County on a property

Post by BobRichards »

This example uses dynamic types...

Code: Select all

dynamic order = {order}
dynamic props = order.Properties;
dynamic property = props[0];
property.County = "Wake";

dynamic address = property.Address;
address.Address1 = "123 Main Street";
address.City = "Raleigh";
And one for static types...

Code: Select all

using System.Collections;  // Non-generic IList namespace

iOrder = {IOrder object}
IList props = (IList)iOrder["Properties"];
IOrderItem property = (IOrderItem)props[0];
property["County"] = "Wake";

IOrderItem address = (IOrderItem)property["Address"];
address["Address1"] = "123 Main Street";
address["City"] = "Raleigh";
And if it really matters, static typing is always slightly faster than dynamic. But for many applications, it really doesn't matter.
Bob Richards, Senior Software Developer, SoftPro
Post Reply