We are trying to post payments to invoices via the SoftPro Select SDK and are receiving 'Cannot access member.' response on some but not all orders.
While debugging I see that orders that accept invoice payments have the following property at the invoice->payments level:
SoftPro.ClientModel.Collections.IBindingListEx.AllowAdd = true
And orders that are return the 'Cannot access member.' error have
SoftPro.ClientModel.Collections.IBindingListEx.AllowAdd = false
Is there somewhere in the SPS Client that I can check this property at the order level?
Cannot add Invoice Payments via the SoftPro Select SDK
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Cannot add Invoice Payments via the SoftPro Select SDK
Please submit your code. I'll take a look at it.
Bob Richards, Senior Software Developer, SoftPro
Re: Cannot add Invoice Payments via the SoftPro Select SDK
The 'Cannot access member.' error is thrown in the AddPayment method @ payments.Add(invPayment); I am able to add notes for these same orders if I bypass the AddPayment. I am also able to add payments to older orders successfully. Thanks!
Code: Select all
private void AddInvoicePaymentsAndNotes(IOrder order, InvoiceModel invoiceModel)
{
//Get the invoice we are paying.
dynamic invoice = GetInvoice(order, invoiceModel);
if (invoice == null)
{
Logger.Info($"Invoice not found: {invoiceModel.SpsInvoiceNumber}");
throw new KeyNotFoundException($"Invoice not found: {invoiceModel.SpsInvoiceNumber}"); // aka NotFoundException
}
// Get payments collection for the invoice.
IList payments = (IList)invoice.Payments;
// Clear the payments
payments.Clear();
// Add the invoice payments in order
invoiceModel.Payments?.OrderBy(p => p.Sort).ToList().ForEach(p => AddPayment(p, payments, order));
// Add the invoice payment notes
invoiceModel.Notes?.ToList().ForEach(n => _noteHelper.AddInvoiceNote(order, invoice, n));
}
private void AddPayment(PaymentModel paymentModel, IList payments, IOrder order)
{
// Create the new payment and add it to the payments collection.
// Payment is always @ the top of the list and if there is a Payment Adjustment it is second
IOrderItem invPayment = order.CreateNew("InvoicePayment");
payments.Add(invPayment);
// Modify properties AFTER it is added to collection.
invPayment.SetProperty("DatePaid", paymentModel.DatePaid);
invPayment.SetProperty("Description", paymentModel.Description);
invPayment.SetProperty("Amount", paymentModel.Amount);
}
Re: Cannot add Invoice Payments via the SoftPro Select SDK
UPDATE:
We found the root cause of this issue was a new COR that was setting invoice payments to read only for certain scenarios. That explains why we are receiving the 'cannot access member' for orders created after a certain date.
Please disregard this question and thank you for your initial response!
We found the root cause of this issue was a new COR that was setting invoice payments to read only for certain scenarios. That explains why we are receiving the 'cannot access member' for orders created after a certain date.
Please disregard this question and thank you for your initial response!
-
- Posts: 1382
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: Cannot add Invoice Payments via the SoftPro Select SDK
I'm glad you found the problem. Thanks for the update!
Bob Richards, Senior Software Developer, SoftPro