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 :
Finance | Project Operations, Human Resources, ...
Unanswered

FormDataSourceEventHandler - OnCreated method

(0) ShareShare
ReportReport
Posted on by 56

Hi Team,

In PurchLine, when we creating a new line  on click on addlines. For example - we created a 5 lines

Then we put Item id , Config Id  and then move to another line.

When we move to another line , I like to insert the PurchLine record to our custom table.

I wrote below code

Form  - PurchTable -- Data source - PurchLine --- Events -- OnCreated

[FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchLine), FormDataSourceEventType::Created)]
    public static void PurchLine_OnCreated(FormDataSource sender, FormDataSourceEventArgs e)
    {
     
    
        PurchQtyTracking      purchQtyTracking;
        PurchLineTracking     purchLineTracking;
        PurchParameters       purchParameters;
        
        FormRun                     formRun = sender.formRun();
        FormDataSource              purchLine_ds = formRun.dataSource(formDataSourceStr(PurchTable,PurchLine)) as FormDataSource;
        PurchLine                   purchLine = purchLine_ds.cursor();


              

        purchParameters = PurchParameters::find();

        // If the  parameter is set to YES then always the PURCH QTY should be default to make zero.
        if (purchParameters.QtyZeroPOLines == NoYes::Yes)
        {
            
            // to insert the current record only with default Purct Qty = 0 for any item, If the parameter set to Yes
            ttsbegin;
            
            purchQtyTracking.PurchId    = purchLine.PurchId;
            purchQtyTracking.ItemId     = purchLine.ItemId;
            purchQtyTracking.ConfigId   = InventDim::find(purchLine.InventDimId).configId;
            purchQtyTracking.RefRecId   = purchLine.RecId;
            purchQtyTracking.PurchQty   = 0;

            purchQtyTracking.doInsert();
            ttscommit;
        }
    }

When I move to another line (without CTRL _S) the OnCreated events is NOT getting called

So, unable to get the table buffer here and It will insert blank line in my custom table.

I refereed few blogs, and the code for sender is different in different blogs.

Kindly verify my code pls. If anything need to change kindly guide me what to modify.

Is I am into correct event?

Pls give me more shed on this.

Thanks!

 

  • André Arnaud de Calavon Profile Picture
    307,784 Super User 2026 Season 2 on at

    Hi Arpan,

    Have you used the debugger to check when your extension is executed or not? Are you using the option "Add line", "Add lines" or "Add products"? If your coding is not getting called, how would it be possible to have an empty line inserted in your custom table?

  • GirishS Profile Picture
    27,845 Moderator on at

    Hi,

    I think you added the same login in the insert method of PurchLine table, right? which you asked in another thread.

    Why are you adding the same logic in create event handler?

    https://community.dynamics.com/365/financeandoperations/f/dynamics-365-for-finance-and-operations-forum/488779/like-to-insert-line-in-custom-table-while-creating-new-line-in-purchase-order/1345420

    Thanks,

    Girish S.

  • Mohit Rampal Profile Picture
    12,573 Moderator on at

    Hi, Instead of OnCreated method of PurchLine DataSource, can you try adding logic in doApply method in PurchQuickQuote form.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 543 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 387 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 185

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans