web
You’re offline. This is a read only version of the page.
close
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

Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365

(3) ShareShare
ReportReport
Posted on by 405
Hello everyone.

I have a question regarding enabling and disabling a specific control within a grid based on the selection of a value from another column.
To clarify, I have a scenario that requires securing one of the columns if its value differs from "PenaltyType::Warning". I used the "OnModified" event of the control itself and wrote the following code:
 
[FormControlEventHandler(formControlStr(JmgParameters, ViolationPenalties_PenaltyCode), FormControlEventType::Modified)]
public static void ViolationPenalties_PenaltyCode_OnModified(FormControl sender, FormControlEventArgs e)
{
    PenaltyType penaltyType = PenaltyTypes::find(sender.valueStr()).PenaltyType;
    FormRun formRun = sender.formRun();
    FormControl cntrol = formRun.design().controlName("ViolationPenalties_Penalty");
    if (penaltyType == PenaltyType::Warning) 
    {
        if (cntrol)
        {
            cntrol.enabled(true);
        }
    }
    else
    {
        if (cntrol)
        {
            cntrol.enabled(false);
        }
    }
}
 

This code works, but the result is different from what I want because it disables the entire column containing the "ViolationPenalties_Penalty" control. However, I need to secure only the field in the specific row I am currently on, without affecting other rows in the column.
I thought about using data source events, but I’m not sure about the correct way to implement this scenario.
Thank you in advance.
Categories:
I have the same question (0)
  • Layan Jwei Profile Picture
    8,114 Super User 2025 Season 2 on at
    Moving this to Finance forum
  • Verified answer
    Layan Jwei Profile Picture
    8,114 Super User 2025 Season 2 on at
    Hi Ali,

    Try the active datasource method instead
    ​​​​​​​

    Thanks,
    Layan Jweihan
    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.

  • Verified answer
    Ali AbdAlNasser Profile Picture
    405 on at
    Hello Layan Jwei,
    I would like to thank you for helping me find the solution. I tried the OnActivated event, and it seemed to be the most appropriate solution, but it became clear to me that I was using the "enabled" function, and it appears that the structure of this function is designed to disable the entire column even if this code is in the OnActivated event. I modified my code and used another function on the cell itself instead of trying to disable the input control. I used the "allowEdit" function instead of "enabled," and the code became as follows:
       [FormDataSourceEventHandler(formDataSourceStr(JmgParameters, ViolationPenalties), FormDataSourceEventType::Activated)]
       public static void ViolationPenalties_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
       {
           ViolationPenalties currentRecord = sender.cursor() as ViolationPenalties;
           if (currentRecord)
           {
               if (PenaltyTypes::findByRecid(currentRecord.PenaltyTypesReferenceGroup).PenaltyType == PenaltyType::Warning)
               {
                   sender.object(fieldNum(ViolationPenalties, Penalty)).allowEdit(true);
               }
               else
               {
                   sender.object(fieldNum(ViolationPenalties, Penalty)).allowEdit(false);
               }
           }
       }
    
    Thank you for your help.
  • Layan Jwei Profile Picture
    8,114 Super User 2025 Season 2 on at
    Hi Ali,
     
    I'm glad your issue is fixed. Please don't forget to verify the answers that helped.
     
     
  • Layan Jwei Profile Picture
    8,114 Super User 2025 Season 2 on at
    Hi Ali,
     
    I think you should verify my answer as well as it mentioned that the correct method to use is the active one.
  • Ali AbdAlNasser Profile Picture
    405 on at
    Hello Layan Jwei,
    I have already marked your response as verified, but it seems there is a problem on my end. I apologize.
  • Layan Jwei Profile Picture
    8,114 Super User 2025 Season 2 on at
    Hi Ali,
     
    Maybe if you go to resources please, then community feedback and mention that you are having an issue in verifying my answer by providing the link to this question
  • Ali AbdAlNasser Profile Picture
    405 on at

    Hello @Layan Jwei,

    I have already sent an email to the community support team three days ago, but no one has responded. So, if possible, please mark your answer as Verified.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans