Page 1 of 2

CSS: Get the next line in a section

Posted: Mon May 25, 2020 1:59 pm
by BobRichards
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.

Code: Select all

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");

Re: CSS: Get the next line in a section

Posted: Wed Jan 13, 2021 3:13 pm
by ckootg
Did this change? We're on version 4.3.41 (4.3.60210.119) and NextAvailableLine isn't available anymore. I'm getting a "Cannot access member." error.

Re: CSS: Get the next line in a section

Posted: Wed Jan 13, 2021 9:38 pm
by BobRichards
I am not aware of a change but it is possible. Please include the source code for your implementation in this area and any stack trace.

Re: CSS: Get the next line in a section

Posted: Wed Jan 13, 2021 9:43 pm
by ckootg
Code:

Code: Select all

var csss = ((dynamic)order).CSSs;
var line = csss[0].Sections["CON"].NextAvailableLine();
Stacktrace:

Code: Select all

   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)

Re: CSS: Get the next line in a section

Posted: Thu Jan 14, 2021 9:25 pm
by BobRichards
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.

Re: CSS: Get the next line in a section

Posted: Thu Jan 14, 2021 9:33 pm
by ckootg
Same "Cannot access member" error.

Here's the stacktrace

Code: Select all

  at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at SoftPro.EntityModel.Entity`1.SoftPro.EntityModel.IEntity.Invoke(String methodName, Object[] args)
   at CSSSection.SoftPro.OrderTracking.Client.Orders.IOrderItem.Invoke(String , Object[] )

Re: CSS: Get the next line in a section

Posted: Thu Jan 14, 2021 9:41 pm
by BobRichards
Could you send me your source, please?

Re: CSS: Get the next line in a section

Posted: Thu Jan 14, 2021 9:42 pm
by ckootg
Just to clarify. The code using the dynamic object to call the NextAvailableLine method worked prior to us upgrading to version 4.3.41.

Re: CSS: Get the next line in a section

Posted: Thu Jan 14, 2021 9:43 pm
by ckootg
I copied your code from this page

Re: CSS: Get the next line in a section

Posted: Thu Jan 14, 2021 9:44 pm
by ckootg
This was the code I copied

Code: Select all

// 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");