Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Disabling Datasource differnet from the sender in EventHandler

(0) ShareShare
ReportReport
Posted on by
Hi everyone, i have task where i need to disable the Datasource(SalesLine)  in the forum SalesTable when the SalesEditLines is open.
to do so i used an event handler like this
[FormEventHandler(formStr(SalesEditLines), FormEventType::Activated)]    public static void SalesEditLines_OnActivated(xFormRun sender, FormEventArgs e)    {        Args    args;        FormRun formRun;        Args = new Args(formStr(SalesTable));        formRun = New FormRun(Args);        FormDataSource SalesLine_ds = formRun.dataSource(formDataSourceStr(SalesTable, SalesLine ));                SalesLine_ds.allowEdit(false);    }
but i always getting /Object reference not set to an instance of an object./ for SalesLine_ds.
thank you in advance for your help.
 
  • Verified answer
    Waed Ayyad Profile Picture
    Super User 2025 Season 1 on at
    Disabling Datasource differnet from the sender in EventHandler
     
    Try this code, as I understand you want to disable caller datasource? but if you can give us more details to help you better.
     
    [FormEventHandler(formStr(SalesEditLines), FormEventType::Activated)] 
    public static void SalesEditLines_OnActivated(xFormRun sender, FormEventArgs e) 
    {     
        FormRun formRun;      
         formRun = sender.args().caller();
        FormDataSource SalesLine_ds = formRun.dataSource(formDataSourceStr(SalesTable, SalesLine ));     
        SalesLine_ds.allowEdit(false);   
    }
     
    Regards,
    Waed Ayyad
    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
     
  • Layan Jwei Profile Picture
    Super User 2025 Season 1 on at
    Disabling Datasource differnet from the sender in EventHandler
    Hi Community User,

    sender here is the SalesEditLines form  -- this form doesn't contain SalesTable or SalesLine, if you debug you'll see that SalesLine_ds is null that's why when the code reaches SalesLine_ds.AllowEdit(false)  you get the object reference error.
    Are you sure you want to disable SalesLine?

    please take a screenshot of you want to disable
    ​​​​​​​
    Thanks,
    Layan Jweihan
     

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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

Overall leaderboard

Product updates

Dynamics 365 release plans