CSS: Get the next line in a section

Discussions related to custom development with Select.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

CSS: Get the next line in a section

Post 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");
Bob Richards, Senior Software Developer, SoftPro
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: CSS: Get the next line in a section

Post 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.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: CSS: Get the next line in a section

Post 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.
Bob Richards, Senior Software Developer, SoftPro
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: CSS: Get the next line in a section

Post 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)
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: CSS: Get the next line in a section

Post 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.
Bob Richards, Senior Software Developer, SoftPro
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: CSS: Get the next line in a section

Post 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[] )
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: CSS: Get the next line in a section

Post by BobRichards »

Could you send me your source, please?
Bob Richards, Senior Software Developer, SoftPro
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: CSS: Get the next line in a section

Post 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.
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: CSS: Get the next line in a section

Post by ckootg »

I copied your code from this page
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: CSS: Get the next line in a section

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