How to Read from IOrderItem Properties

Discussions concerning general integration topics.

Moderator: Phil Barton

Post Reply
Posts: 1382
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC

How to Read from IOrderItem Properties

Post by BobRichards »

The Select Order Model uses IOrderItems as the building block for a vast number of object from Policies to Settlement Agents. To the developer, it provides a simple pattern for interaction despite the differences between the complex objects (Policies have Billcodes and Settlement Agents have Logos). In this topic we will discuss reading IOrderItem properties. Due to length constraints, I have to assume you know a little about IOrderItems. If not, create a new post. Be aware that this topic is the sister to How to Write to IOrderItem Properties.

I am going to use an Address object as the IOrderItem. If you have an address, you can always get its first address line as follows:

Code: Select all

# Walk down each level of child objects from the order to the first property's Address1 line.
IList properties = (IList)order.GetProperty("Properties");
IOrderItem firstProp = (IOrderItem)properties[0];
IOrderItem propAddr = (IOrderItem)firstProp.GetProperty("Address");
string address1 = (string)propAddr.GetProperty("Address1");
I can do this because I know an order will always have at least a single property. GetProperty() will query the IOrderItem for the passed property name and return its value as an Object (which includes null if the value is a Reference type) or null (if property doesn't exist). Notice we have to cast the value apppropriately. Do this safely because you can't coerce a null to an Int32.

So does our luck hold with GetProperty() for any property?

Code: Select all

// Add this line below the "string address1 = ..." from above
string city = (string)propAddr.GetProperty("City");
For me, the code throws an exception: Error - Operation is not valid due to the current state of the object. Why? Because the Foreign address box was checked. If the box is checked then the City/State/Zip properties are unsupported and the ForeignAddress property is supported. You can test for properties being supported/unsupported because of the current order state as follows:

Code: Select all

string city = null;
if (propAddr.HasProperty("City") && propAddr.GetIsSupported("City"))
    // Get city if property not foreign.
    city = (string)propAddr.GetProperty("City");
Now we get the city name if one is available (of course, since this may be user entered information. Even if the property is supported there is no guarantee the value is set correctly - can't have everything).

You should use the HasProperty()/GetIsSupported() as a pair out of habbit. They are very fast and this is a quick routine to determine what type of IOrderItem you are inspecting. For instance, if you have a Task but don't know if it is a Checklist Task or a Requested Task, you can use the HasProperty() since only a Requested Task has a property named "BillCode".

* Full disclosure - The Address object has a boolean property that allows you to know the Foreign address mode (propAddr.GetProperty("UseForeignAddress") and that is what you should be using for addresses. Addresses do make for a good example of GetIsSupported(), though.
Bob Richards, Senior Software Developer, SoftPro
Post Reply