web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Integrating Financial dimension form causing 2 inserts

(0) ShareShare
ReportReport
Posted on by 506

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.

*This post is locked for comments

I have the same question (0)
  • _MGP Profile Picture
    506 on at

    Still banging head against brick wall with this one.

    I've removed the code that was defaulting and making certain dimensions mandatory and the problem still persists.

    When the dimensions are inherited from the Customer and no further edits are made to any dimension then the Sales Order saves fine.

    Sales-order-2.png

    Otherwise, any change to a dimension results in an error.

    Sales-order-2.png

    Sales-order-3.png

    The integration of the financial dimensions controller with the existing form (SalesCreateOrder) is the problem but I'm not sure how to troubleshoot further.

    Clicking on "OK" button triggers 2 writes to the SalesTable's datasource.

    Any pointers anyone??

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    As per my understanding, you introduced Financial dimensions on salesordercreate form, in which on selecting customer these dimensions are defaulted from the customer and later on has the option for the user to change them. I performed following steps and able to achieve this. Please follow them and let me know if anything is missing.

    1. Declared DimensionDefaultingController  in the classDeclaration of the form.

    DimensionDefaultingController   dimDefaultingController;

    2. Added TabPage TabFinancialDimensionLine to the form.

    3. In the init method of the form, added following code

    Path: \Forms\SalesCreateOrder\Methods\init

     DimensionDefaultingController::initContainerId(tabFinancialDimensionLine, 2);
        dimDefaultingController = DimensionDefaultingController::constructInTabWithValues(true, true, true, 0, this, tabFinancialDimensionLine, "@SYS138487");
        dimDefaultingController.parmAttributeValueSetDataSource(salesTable_ds, fieldStr(SalesTable, DefaultDimension));  

    4. In the active method of the form, added following code by overwriting active method

    Path: \Forms\SalesCreateOrder\Data Sources\SalesTable\Methods\active

    public int active()
    {
        int ret;
    
        ret = super();
    
        dimDefaultingController.activated();
    
        return ret;
    }

    5. In the write method, added following code just after ttscommit statement.

    Path: \Forms\SalesCreateOrder\Data Sources\SalesTable\Methods\write

    SalesCreate-_2D00_-Write.jpg

    6. In the pageActivated method, added the below code.

    Path: \Forms\SalesCreateOrder\Designs\Design\[Tab:TabOthers]\[TabPage:TabFinancialDimensionLine]\Methods\pageActivated

    public void pageActivated()
    {
        dimDefaultingController.pageActivated();
    
        super();
    }


  • _MGP Profile Picture
    506 on at

    Thanks Chaitanya - that is a perfect answer and is very much appreciated.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
Basit Profile Picture

Basit 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans