Hi,
I'm adapting 2 forms so that users are forced to save specific Financial dimension values before saving each record. I've customised Sales orders (SalesCreateOrder form) and Projects (ProjTableCreate).
Creating new Projects work fine, but in the create Sales orders form when I change a financial dimension value that has not been defaulted and try to save it says:
"Cannot create a record in Sales orders (SalesTable). Sales order: SO000046, CompanyName. The record already exists."
However, when I cancel out of the form and refresh the SO's the new SO is created with all intended dimension values.
I want to find a way to prevent the error (and understand the problem also :-) ).
The init() methods of the forms are done in similar way
SalesCreateOrder form
void init()
{
....
dimDefaultingController = DimensionDefaultingController::constructInTabWithValues(true, true, true, 0, this, TabFinancialDimensions, "@SYS138487");
dimDefaultingController.parmAttributeValueSetDataSource(salesTable_ds, fieldStr(SalesTable, DefaultDimension));
}
and ProjTableCreate
void init()
{
....
dimDefaultingController = DimensionDefaultingController::constructInTabWithValues(true, true, true, 0, this, TabFinancialDimensions, "@SYS138487");
dimDefaultingController.parmAttributeValueSetDataSource(projTable_ds, fieldStr(ProjTable, DefaultDimension));
}
On ProjTable I've done a post-Event handler on initValue() which sets the DefaultDimension. I've had to comment out the default behaviour in initFromCustTable() and initFromInvoice() that normally overrides the default dimension value.
On SalesTable I've done a similar thing but not identical. Within initValue() I set the salesTable.DefaultDimension as follows:-
void initValue(SalesType _salesType = SalesParameters::find().OrderType)
{
this.SalesType = _salesType;
super();
MGPFinDimDefault::setSalesTableDefaultDimension(this);
this.initValue_Server();
}
I've also had to amend an IL method, initFromCustTableIL()
private static server container initFromCustTableIL(container _salesTableContainer)
{
....
//salesTable.DefaultDimension = salesTable.copyDimension(custTable.DefaultDimension);
//replaced by
MGPFinDimDefault::setSalesTableDefaultDimension(salesTable);
....
// there is an identical line replaced in the same way further down this method call
}
I've also tried commenting out the lines instead but the result is the same.
I've debugged and can see the insert() method on the SalesTable being called twice in succession resulting in the error.
Why does a selection of the Financial dimension cause this double insert error?
Will share more code as needed.
Thanks.