If you want to add a line to a CSS settlement, it takes two steps - if you can't find a free line among the existing ones, you need to create one. This is the procedure to follow. Also, be aware that sections only allow certain number of lines.
IOrder order = ...
// Get the first CSS.
IList CSSs = (IList)order.GetProperty("CSSs");
IOrderItem css = (IOrderItem)CSSs[0];
// Look up the section from the dictionary by Section Code.
IDictionary sections = (IDictionary)css.GetProperty("Sections");
IOrderItem section = (IOrderItem)sections["CON"];
// Get the next line that has not been used already.
IOrderItem nextLine = (IOrderItem)section.Invoke("NextAvailableLine");
// Make sure we got a line since there is a maximum number the section can hold (typically around 100).
if (nextLine == null)
{
// We can't add the line. Do something!
return;
}
// Set description on first charge. This part is same for all examples...
IList charges = (IList)nextLine.GetProperty("Charges");
IOrderItem firstCharge = (IOrderItem)charges[0];
firstCharge.SetProperty("Description", "We created this charge");
at SoftPro.EntityModel.Collections.EntityCollection`2.ValidateAdd(T item)
at SoftPro.EntityModel.Collections.EntityCollection`2.InsertItem(Int32 index, T item)
at SoftPro.EntityModel.Collections.SnapshotCollection`1.Add(T item)
at CSSSection.NextAvailableLine()
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
The "NextAvailableLine" method is a public method but is not part of the IOrderItem interface (or any other API interface/class available at compile time) so the compiler doesn't know anything about it. That's why it is failing to build for you.
Instead, you have to use a reflection mechanism to find the method at runtime (late binding). Use the "invoke" example in the original post to resolve and execute the method.
// Get the first CSS.
IList CSSs = (IList)order.GetProperty("CSSs");
IOrderItem css = (IOrderItem)CSSs[0];
// Look up the section from the dictionary by Section Code.
IDictionary sections = (IDictionary)css.GetProperty("Sections");
IOrderItem section = (IOrderItem)sections["CON"];
// Get the next line that has not been used already.
IOrderItem nextLine = (IOrderItem)section.Invoke("NextAvailableLine");