.CreateNew() can be considered a helper method. It makes sure that your sales order object and it's properties are properly cleared and set up as a new sales order (i.e. property defaults are set, collection properties cleared, insert flags set, etc.).
You should always use .CreateNew() to create new sales orders. A debtor is always required for a sales order, so .CreateNew() accepts one as a parameter and sets the .Debtor property for you (well, it actually accepts a DebtorID value and does a .Debtor.Read()).
You could choose to not use the .CreateNew() method and set/clear properties manually, but that's a lot of work and opens you up to missing something.
Finally, the reason the .Debtor property is read-only, is that it is an entity - you don't set it, you do a .Read() on it, thus:
- Code: Select all
SalesOrder.Debtor.Read(myDebtorID)
So the idea with our objects is that you use a factory to instantiate it. Then you can do a .CreateNew() to create a new record, or perhaps you will do a .Read() to read an existing record. You may very well do a .Read(), look at some stuff, and then call a .CreateNew()
on that same object to create a new record. The object is created once, and you use it over and over for different operations.