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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Initialize CustAccount in SalesCreateOrder form

(0) ShareShare
ReportReport
Posted on by 8
Hello,
I have a requirement to add a button on a custom form which will open the SalesCreateOrder form (to create a new sales order).
There is a custom customer account (TSTCustAccount) setup in CustParameters which the form needs to automatically initialize with.
I have added a new boolean parm method in the class extension of SalesTableForm.
I have added a new button in my custom form and added the following codes in the clicked method :
 
SalesTableForm salesTableForm = SalesTableForm::construct(SalesTableFormId::None, null);
salesTableForm.tstParmTest(true);
salesTableForm.create();
 
I have then added a logic in the post init of the SalesCreateOrder form extension:
 
if (salesTableForm.tstParmTest())
        {
            CustParameters tstCustParameters = CustParameters::find();
 
            if (tstCustParameters.TSTCustAccount)
            {
                SalesTable.CustAccount(tstCustParameters.TSTCustAccount);
                SalesTable.modifiedField(fieldNum(SalesTable, CustAccount));
            }

        }
 
However, the customer account field is still empty.
I have tried doing in the SalesTable_DS.initValue, but it is still empty.
Is there another way to do this particular requirement?
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,679 Most Valuable Professional on at
    Initialize CustAccount in SalesCreateOrder form
    init() method of a form just initialized form controls, data source objects etc., but no data is loaded and no new record is created at the moment. That happens later, when the form is actually executed.
     
    A good method for your purpose is initValue() and the data source, which is called when a new record is being created. But don't extend it; instead, look at what code it already contains. It calls initValues() of SalesTableForm, but we won't extend that either. We can see that this method takes the value of CustAccount from custAccount(), which is a parameter method.
     
    When we look at where the custAccount value is used, we'll find that we can simply pass it to create() method:
    SalesTableForm salesTableForm = SalesTableForm::construct(SalesTableFormId::None, null);
    salesTableForm.create(CustParameters::find().TSTCustAccount);
  • Verified answer
    Jason0810M Profile Picture
    8 on at
    Initialize CustAccount in SalesCreateOrder form
    Hello Martin,
    I have tried it and it did not work.
    I have tried another approach and it seems to work fine.
     
    CustParameters tstCustParameters = CustParameters::find();
    SalesTableForm salesTableForm = SalesTableForm::construct(SalesTableFormId::None, null);
    salesTableForm.tstParmTest(true);
    salesTableForm.custAccount(CustParameters.TSTCustAccount);
    salesTableForm.create();
     
    I have added an override of the SalesTableForm.initValues() as follows.
     
    next initValues();
    if (this.tstParmTest() && SalesTable.CustAccount)
    {
    //call logic to initialise standard fields as per customer selected
        SalesTable.modifiedField(fieldNum(SalesTable, CustAccount));
    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans