Skip to main content

Notifications

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 342
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:
  • Ali AbdAlNasser Profile Picture
    Ali AbdAlNasser 342 on at
    Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365

    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.

  • Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365
    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
    Ali AbdAlNasser 342 on at
    Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365
    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
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365
    Hi Ali,
     
    I think you should verify my answer as well as it mentioned that the correct method to use is the active one.
  • Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365
    Hi Ali,
     
    I'm glad your issue is fixed. Please don't forget to verify the answers that helped.
     
     
  • Verified answer
    Ali AbdAlNasser Profile Picture
    Ali AbdAlNasser 342 on at
    Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365
    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.
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365
    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.

  • Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    Enable/Disable a Field in a Grid Row Based on Another Column's Value in Dynamics 365
    Moving this to Finance forum

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans