web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to disable editing on all form datasources?

(1) ShareShare
ReportReport
Posted on by 845
Hi, I would like to disable editing on a form after a specific condition is met. I have already tried this code, but unfortunately without results. Can someone help?
 
[FormDataSourceEventHandler(formDataSourceStr(PurchReqTable, PurchReqTable), FormDataSourceEventType::Activated)]
public static void PurchReqTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
    FormDataSource purchReqTable_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, PurchReqTable));
    FormDataSource purchReqLine_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, PurchReqLine));
    FormDataSource inventDim_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, InventDim));
    FormDataSource businessJustificationHeader_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, BusinessJustificationHeader));
    FormDataSource businessJustificationLine_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, BusinessJustificationLine));
    FormDataSource logisticsPostalAddressLine_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, LogisticsPostalAddressLine));
    FormDataSource purchReqLineKMCollection_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, PurchReqLineKMCollection));
    FormDataSource purchReqExternalSource_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, PurchReqExternalSource));
    FormDataSource purchReqLineTaxExtensionIN_ds = sender.formRun().dataSource(formDataSourceStr(PurchReqTable, PurchReqLineTaxExtensionIN));


    PurchReqTable purchReqTable = purchReqTable_ds.cursor();

    if(purchReqTable.myCondition())
    {
        purchReqTable_ds.allowEdit(false);
        purchReqLine_ds.allowEdit(false);
        inventDim_ds.allowEdit(false);
        businessJustificationHeader_ds.allowEdit(false);
        businessJustificationLine_ds.allowEdit(false);
        logisticsPostalAddressLine_ds.allowEdit(false);
        purchReqLineKMCollection_ds.allowEdit(false);
        purchReqExternalSource_ds.allowEdit(false);
        purchReqLineTaxExtensionIN_ds.allowEdit(false);

    }
}
 
  • Anton Venter Profile Picture
    21,236 Super User 2026 Season 2 on at
    Hello,
     
    Is your condition actually true? Perhaps the standard code is overriding your change after your code has executed. Have you debugged your code to see what's going on?
  • Shooowtek Profile Picture
    845 on at
    Yes, I debugged the code and my condition is true. I can't find the reason why disabling editing doesn't work.
  • Suggested answer
    AtulMP Profile Picture
    4 on at

    Hello,

    It seems you're using allowEdit(false) based on certain conditions in your form's data source, likely through an event handler. Instead of relying on event handlers, you can simplify your approach by directly overriding the form methods.

    For example, you can set the edit permission like this:

    yourdatasource_ds.allowEdit(false);

    Or, for a specific field, you can use:

    yourdatasource_ds.object(fieldNum(datasourcetable, field)).allowEdit(false);

    This approach reduces complexity and keeps your code organized. For further insights, you may find this blog helpful: Enable/AllowEdit of DataSource Field.

    If you have any questions or need more information, feel free to ask!

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    This activated event gets called from super() of active method. But I feel, the standard is overriding your logic. So I would suggest you to write code post next of active method.
  • Suggested answer
    Waed Ayyad Profile Picture
    9,218 Super User 2026 Season 2 on at
    Hi,
     
    Try to use active method through COC, does you condition depend on certain changes on the form itself? Try to add your changes to the init method of the form also.
     
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • André Arnaud de Calavon Profile Picture
    307,271 Super User 2026 Season 2 on at
    Hi Shooowtek,

    As mentioned by others, some standard logic might overwrite your coding. During debugging you should not only focus on your own coding, but also what happens after that. 

    What is the exact condition when the data sources should be read-only? Depending on the complexity there can be another way to achieve your requirement by developing a security policy to manage CUD actions.
  • Waed Ayyad Profile Picture
    9,218 Super User 2026 Season 2 on at
    Hi,

    Is your issue resolved?  If yes, mark the answers that helped you as verified.

    Thanks
    Waed Ayyad

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 515 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 417 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 360

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans