Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Disabling Datasource d...
Finance forum
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 3,904 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,845 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
     

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,768 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,985 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans