Problems setting County on a property
-
- Posts: 92
- Joined: Tue Feb 04, 2014 3:34 pm
Problems setting County on a property
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
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
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Problems setting County on a property
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
-
- Posts: 92
- Joined: Tue Feb 04, 2014 3:34 pm
Re: Problems setting County on a property
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
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
-
- Posts: 92
- Joined: Tue Feb 04, 2014 3:34 pm
Re: Problems setting County on a property
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";
Should the code I have below work? Isn't that equivalent to what you are suggesting?
order.Properties[0].County = "Orange";
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Problems setting County on a property
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:
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
Bob Richards, Senior Software Developer, SoftPro
-
- Posts: 92
- Joined: Tue Feb 04, 2014 3:34 pm
Re: Problems setting County on a property
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
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
Re: Problems setting County on a property
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";
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";
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Problems setting County on a property
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:
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 property.
property.County = "Wake";
// Static indexer.
((IOrderItem)property)["County"] = "Wake";
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
Re: Problems setting County on a property
ok great.
What about sub structures though..
i.e. I need to set Line1 and City of Address under Property
What about sub structures though..
i.e. I need to set Line1 and City of Address under Property
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Problems setting County on a property
This example uses dynamic types...
And one for static types...
And if it really matters, static typing is always slightly faster than dynamic. But for many applications, it really doesn't matter.
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";
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";
Bob Richards, Senior Software Developer, SoftPro