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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to save the SalesId into my Custom table when the Sales Order is created

(0) ShareShare
ReportReport
Posted on by 147
I have a question regarding the customization in D365FO.
 
I have a requirement to create two checkboxes field in a custom table, named ADS_SalesOrderCBTable. The table is added as the formDataSource in the SalesTable form.
//
 
The table contains one field which needs to store the SalesId. I have created the foreign key relation to the custom SalesId field.
 
////
 
However, I find that when I create the sales order and check the checkbox field, the SalesId will not the stored in the custom table. There is only the checkbox value recorded.
////
 
So I would like to ask to get the SalesId value into my custom table, ADS_SalesOrderCBTable, is it I need to write some code such as initFrom in the table to get the SalesId from my sales order? If yes, the initFrom method should be called in the form class, am I right?
 
Kindly please correct me if I get anything wrong.

Thank you.

Regards,
Yue Zhen
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    Hi @Yue Zhen,
     
    i guess you can add extension on table SalesTable and then override Insert method.
    e.g.
    [ExtensionOf(TableStr(SalesTable))]
    final class SalesTable_Table_Extension
    {
        void insert(boolean _skipMarkup = false)
        {
    		ADS_SalesOrderCBTable		SalesOrderCBTable;
            next insert(_skipMarkup);
    		SalesOrderCBTable.clear();
    		ttsBegin;
    		SalesOrderCBTable.ADS_SalesId = this.SalesId;
    		// ....
    		SalesOrderCBTable.insert();
    		ttsCommit;
        }
    }
    Best regards,
    Mohamed Amine MAHMOUDI
  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at
    Please tell us more about the business requirement. It's difficult to design a solution without knowing how it should work.
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi Yue,
     
    I think we need more details on why you added this table from a business point of view.
     
    But in general, do you really need to show this field on the form? because what you can do, is that on the insert method of the salesTable, you can insert into your new table
     
    Thanks,
    Layan Jweihan 
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Yue Zhen Profile Picture
    147 on at
    This reply is to clarify my business requirement.

    I need to create two checkboxes and other fields that related to E-Invoice. According to the business requirement, these custom fields should be able to be edited even after the sales order is posted. (A subform that contains only the custom fields will be created later to allow users to modify the custom fields values after invoice posted.)
     
    So, I create the fields in an custom table named, ADS_SalesOrderCBTable. Currently, there are three fields in this table which are SalesId, EInvoiceCheckbox and ConsoEInvCheckbox. The SalesId in the custom table will play the role to identify which sales order the record is referring to.

    For now, I can see a record is created in the ADS_SalesOrderCBTable when I clicked save on the SalesTable form. However, the SalesId field of ADS_SalesOrderCBTable table is still empty.

    Yet, my question is how can I pass the SalesId value into my ADS_SalesOrderCBTable table when I save the Sales Order record? 
     
    I try to refer to how MS did for SalesLine record, but I find it is complicated and I cannot understand. 
  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at
    Please show us your current code and tell us what you found when you run your code in debugger.
  • Yue Zhen Profile Picture
    147 on at
    .[ExtensionOf(tableStr(SalesTable))]
    final class SalesTable_ADSEInvoice_Extension
    {
        void insert(boolean _skipMarkup)
        {
            next insert(_skipMarkup);
            ads_SalesOrderCBTable salesOrderCBTable;
            salesOrderCBTable.clear();
            
            salesOrderCBTable.ads_SalesId = this.SalesId;
            salesOrderCBTable.insert();
            
        }
    }

    Currently, I am using this code. When I do testing, I find out that there is one line record with the salesID created in ADS_SalesOrderCBTable, with the initial both checkbox values = 0.
     
    After that, I try to check the consolidate e-invoice checkbox in the form.
     
    I find out it create a new line of record without salesID but with consolidate e-invoice checkbox value = 1.
     
    Then I refresh the form and the Consolidate e-invoice checkbox is back to uncheck.
     
    I check the same checkbox again and save. I run the SQL and notice that the record line with SalesID = 'MYMF-000766' is updated.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
    Hi @Yue Zhen ,
     
    you forgot to delete or comment out the old code in the initFromSalesTable method.
     
    Best regards,
    Mohamed Amine Mahmoudi
  • Yue Zhen Profile Picture
    147 on at
    Hi Sir Amine,
     
    Based on my latest SQL screenshot, I think I have get the thing correct. I changed my form datasource's link type from Outer Join to Delayed. After that, it seems like it can update checkbox value in the line with SalesID. Hmm, I did it but seems I am not really understand. 
  • Suggested answer
    Nisha Soni 2709 Profile Picture
    on at
    You can try this below code to pass your salesid from saletable to your custom table
     
    [ExtensionOf(tableStr(SalesTable))]
    final class SalesTable_ADSEInvoice_Extension
    {
        void insert()
        {
            next insert();
            if(this.EinvoiceCheckbox == Noyes::Yes)
            {
                    ads_SalesOrderCBTable salesOrderCBTable;
                    salesOrderCBTable.clear();
                    salesOrderCBTable.ads_SalesId = this.SalesId;
                    salesOrderCBTable.insert();
            }
        }
    }
  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at
    Yue Zhen, please tell us how you configured your data source. Have you selected SalesTable as the parent data source? What LinkType have you used?

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 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans