How to Write to IOrderItem Properties

Discussions concerning general integration topics.

Moderator: Phil Barton

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

How to Write to 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 writing to 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 Read from IOrderItem Properties.

For this example, I am going to use an invoice that has been previously set up and is ready to send. It currently has a Status of Pending. We'll get the invoice number then change it. Last step is to save the order with its changes.

Code: Select all

using (IOrder order = os.OpenOrder(oi, OrderEditMode.ReadWrite))
{
    IList invoices = (IList)order.GetProperty("Invoices");
    IOrderItem firstInv = (IOrderItem)invoices[0];
	
    // Read current invoice number value.
    string initialValue = (string)firstInv.GetProperty("Number");

    // Now change it to new value.
    firstInv.SetProperty("Number", "22222");

    // Save the modified order.
    os.ApplyChanges(order);
    os.CloseOrder(order);
}
Typically this is all there is to know. But there are times that order properties are not writable. By setting the invoice status to Sent and saving the order, Select core rules will set the "Locked" aspect on the property to prevent any changes at this time. This is subtly different from the "ReadOnly" aspect that other core rules may set but the net effect is the same - the user (and its proxy the API) may not write to the property.

If you attempt to set the invoice number now that the status is Sent, the code throws an exception: Error - Cannot access member. You can test for properties being Locked/ReadOnly because of the current order state as follows:

Code: Select all

if (!(firstInv.GetIsReadOnly("Number") || firstInv.GetIsLocked("Number")))
{
     firstInv.SetProperty("Number", "22222");
}
Best practice: If in doubt, always test the properties in production code and don't rely on try/catch blocks.
Bob Richards, Senior Software Developer, SoftPro
enendza
Posts: 75
Joined: Wed Oct 16, 2019 12:22 pm

Re: How to Write to IOrderItem Properties

Post by enendza »

Thanks - I was looking at the object model for CDFs and found this object structure - see attached - seems like these are the collection of objects that I need to set Payee one based on business rules that I have.

So, I can do a LINQ expression to get the items that I need but now I am stuck trying to figure out where to set the "Payee" property - I don't see it in the list of properties but it is on the UI?

Advice?

Emma
Attachments
Purchase CD Fees Screen.png
Purchase CD Fees Screen.png (300.23 KiB) Viewed 2920 times
CDFModel.png
CDFModel.png (118.78 KiB) Viewed 2920 times
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: How to Write to IOrderItem Properties

Post by BobRichards »

The list of Items you found contains all the IOrderItems in the order. You would only see a Payee object if one has been previously created. I always start with the line entity then navigate by getting the appropriate properties to get to the payee collection.

Each CDFLine entity has a Charges collection that is a list of charges for that line.
Each CDFCharge has a Payees collection and Payors collection.

Code: Select all

IList charges =(IList) line.GetProperty("Charges")
charge = (pick from list)

IList payees =(IList) charge.GetProperty("Payees")
payee = (pick from list)
Bob Richards, Senior Software Developer, SoftPro
enendza
Posts: 75
Joined: Wed Oct 16, 2019 12:22 pm

Re: How to Write to IOrderItem Properties

Post by enendza »

Thanks I will give it a try.
enendza
Posts: 75
Joined: Wed Oct 16, 2019 12:22 pm

Re: How to Write to IOrderItem Properties

Post by enendza »

Hi -

I used to get an error about the Payee being empty so I added this code.

Basically get the charge object for the line that I am working with and set the Payee Contact object to my settlementAgent object (i.e. payees1.FirstOrDefault().SetProperty("Contact", settlementAgentA as IContact);)

BUT then when I save I get these errors:

CDF To field on CDF line C.03 is a required field.
CDF To field on CDF line C.04 is a required field.
CDF To field on CDF line C.05 is a required field.
etc...

What "To" field is this referring to? Can't find the To property.

Thanks in advance for your help,

Emma
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: How to Write to IOrderItem Properties

Post by BobRichards »

For items like this, you need to start the Select client app and navigate to the settlement section. Then you will see a column named "To".
Capture-Line.PNG
Capture-Line.PNG (7.45 KiB) Viewed 2879 times
Determine Property Name
Now put your cursor in one of the To field boxes and press Alt+F6 and a popup will show the property name.
Capture-FieldBox.PNG
Capture-FieldBox.PNG (14.55 KiB) Viewed 2879 times
Field Code Browser
Another useful thing to do is to display the Field Code Browser (FCB) and press the link icon at the top of the FCB. Now when you click in an order field box, the FCB will show you the location of this property hierarchically at the top. It shows the property name and context at the bottom.
Capture-FCB.PNG
Capture-FCB.PNG (12.97 KiB) Viewed 2879 times
Bob Richards, Senior Software Developer, SoftPro
enendza
Posts: 75
Joined: Wed Oct 16, 2019 12:22 pm

Re: How to Write to IOrderItem Properties

Post by enendza »

Many thanks that works great!!
Post Reply