Skip to main content

Notifications

Announcements

No record found.

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

Disabling Datasource differnet from the sender in EventHandler

(0) ShareShare
ReportReport
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 3,431 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 4,220 Super User 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

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284,876 Super User

#2
Ludwig Reinhard Profile Picture

Ludwig Reinhard Microsoft Employee

#3
Martin Dráb Profile Picture

Martin Dráb 225,425 Super User

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans