Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Initialize CustAccount in SalesCreateOrder form

(0) ShareShare
ReportReport
Posted on by 250
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?
  • Verified answer
    Jason0810M Profile Picture
    Jason0810M 250 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));
    }
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,370 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);

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans