Skip to main content

Notifications

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

Disabling Datasource differnet from the sender in EventHandler

Posted on by 52
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
    Waed Ayyad 6,301 Super User 2024 Season 2 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
    Layan Jwei 7,345 Super User 2024 Season 2 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans