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
    8,485 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
    7,855 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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Martin Dráb Profile Picture

Martin Dráb 601 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 416

#3
Adis Profile Picture

Adis 384 Super User 2025 Season 1

Product updates

Dynamics 365 release plans