Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Form grid field enable...
Finance forum
Answered

Form grid field enable if condition met

Posted on by 367
Hello 

I 've got a form grid where i have rows, i need to create some behavior.

When i click the checkbox on row1, the other checkbox from row2(row3,4 ...) must be disable,  but not the one i checked first and when i uncheck the checkbox on row1, the other checkbox from row2 must be enable.

How to do that ?


Here's the grid sample.

Regards
  • Verified answer
    Awaxx Profile Picture
    Awaxx 367 on at
    Form grid field enable if condition met
    Hello guys,

    I used a validate method and add a warning, that's seems to me the best solution.

    ​​​​​​​Thanks guys
  • Waed Ayyad Profile Picture
    Waed Ayyad 3,758 on at
    Form grid field enable if condition met

    Hi,

    I have a question about this requirement: what should be the default case? Do all lines have to be enabled or disabled?

    Thanks,
    Waed Ayyad
     
     
  • Layan Jwei Profile Picture
    Layan Jwei 4,742 Super User on at
    Form grid field enable if condition met
    Hi Awwax,
     
    Yes i understand that's why i said where recId!= currentRecId and that's why i mentioned modified method and init method

    So for example in general, if let's say the grid is salesLine, and you would like to get all other records except for the one you are standing on, then you would write sth like this:
    While select salesLine where salesLine.SalesId == this.SalesId && salesLine.RecId != this.RecId

    Can you show us what you did and tell us the wrong behavior that happens so that we can help

    The active method could also work as bharani suggested -- maybe it's a better suggestion and maybe what i suggested at first won't work.
    You could write sth that says if no checkBox is ticked as true in the whole grid then make all editable
    If one is ticked as true, then make others disabled
    ​​​​​​​
    So maybe try sth like this:
    [ExtensionOf(formDataSourceStr(SalesTable, SalesLine))]
    final class SalesTableFormDatasource_Extension
    {
        public int active()
        {
            int ret;
    
            ret = next active();
    
            if(ret)
            {
                SalesLine salesLineLocal = this.cursor();
    
                SalesLine salesLineCount;
                select count(RecId) from salesLineCount where salesLineCount.SalesId == salesLineLocal.SalesId && salesLineCount.CheckBoxField == NoYes::Yes ;
    
                If (salesLineLocal.CheckBoxField == NoYes::Yes || salesLineCount.RecId == 0)
                {
                    this.object(fieldNum(salesLine, CheckBoxField)).allowEdit(true);
                }
                else
                {
                    this.object(fieldNum(salesLine,CheckBoxField)).allowEdit(false);
                }
            }
    
            return ret;
        }
    }
    

    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.
  • Awaxx Profile Picture
    Awaxx 367 on at
    Form grid field enable if condition met
    Hi guys, 

    Thanks for replying.

    You must understand that when i'm checking the checkbox on a specific row, only other ones must be disabled, the checked one must be editable in case i need to uncheck it to make other ones enabled.

    For now, i tried many ways but i'm not able to make enable the checked on when disabling the others.

    Do you have some clues ?

    Regards.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,528 Super User on at
    Form grid field enable if condition met
    In the active method of that line datasource just check if any of the other line is checked. If checked then make the current row enum field disabled and vice versa.
  • Layan Jwei Profile Picture
    Layan Jwei 4,742 Super User on at
    Form grid field enable if condition met
    Hi,
     
    Do you mean that if one checkBox in the grid is ticked as true, then all other records should have their checkBoxes as disabled? And if no checkBox in the grid is ticked as true, then all checkBoxes should be enabled?
     
    If yes, then on the modified method of the checkBox, you can check if the current value is true and disable all other checkboxes in the grid (recId != CurrentRecId) and if the value is false, then you can enable all of them. I think you would also need the code in the init method of the form so that the code is reflected when you first open the form
     
    Maybe show us your code and we can help you from there
     
    Or why not on the validate method only allow one checkbox to be ticked as true? Would it suit your requirement? I mean if you try to tick another checkBox a warning will appear saying only one checkBox can be set as true and it will prevent you from saving
     
    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.

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... 287,914 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans