Skip to main content

Notifications

Announcements

No record found.

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

FormDataSourceEventHandler - OnCreated method

(0) ShareShare
ReportReport
Posted on by

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!

 

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: FormDataSourceEventHandler - OnCreated method

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

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: FormDataSourceEventHandler - OnCreated method

    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.

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,162 Super User 2025 Season 1 on at
    RE: FormDataSourceEventHandler - OnCreated method

    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?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans