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