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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Is it possible to override selectionChange method on extended form

(0) ShareShare
ReportReport
Posted on by 1,836
i have extended form which is having a combox  on the selection of specific value on combo box i want to make the field on form data source non editable so i have written the selection change method on that combo box control but it is not working can any one guide me on this . 
my code is below 
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    is it possible to ovrride selection chsnge method on extended form
    I am using the code below , is it right , plz let me know if i am missing something.
    [ExtensionOf(formstr(ProjWorkBreakdownStructureV2))]
    final class DT_PSAActivityEstimatesDK_Extension
    {
     [Control("ComboBox")]
        class ViewMode
        {
            public int selectionChange()
            {
                FormRealControl   PSAActivityEstimates_ProjectValue;
    
                if (this.selection() == enum2Int(ProjWorkBreakdownStructureViewMode::Scheduling))
                {
                    boolean schedulingMode = ViewMode.selection() == enum2int(ProjWorkBreakdownStructureViewMode::Scheduling);
                     PSAActivityEstimates_ProjectValue.allowEdit(schedulingMode);   
                }
                else if (this.selection() == enum2Int(ProjWorkBreakdownStructureViewMode::CostEstimates))
                {
                     PSAActivityEstimates_ProjectValue.allowEdit(true);   
                }
    
                return super();
            }
    
        }
    
    }
     
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at
    is it possible to ovrride selection chsnge method on extended form
    Code below is totally wrong - You need to write extension for formcontrolString not formStr.
    Also, the next keyword is missing in selection changed method.
    [ExtensionOf(formcontrolstr(ProjWorkBreakdownStructureV2, ControlName))]
    final class DT_PSAActivityEstimatesDK_Extension
    {
            public int selectionChange()
            {
                int ret = next selectionChange();
                FormRealControl   PSAActivityEstimates_ProjectValue;
    
                if (this.selection() == enum2Int(ProjWorkBreakdownStructureViewMode::Scheduling))
                {
                    boolean schedulingMode = ViewMode.selection() == enum2int(ProjWorkBreakdownStructureViewMode::Scheduling);
                     PSAActivityEstimates_ProjectValue.allowEdit(schedulingMode);   
                }
                else if (this.selection() == enum2Int(ProjWorkBreakdownStructureViewMode::CostEstimates))
                {
                     PSAActivityEstimates_ProjectValue.allowEdit(true);   
                }
                return ret;
               
            }
    
        }
    
    }
  • Dineshkarlekar Profile Picture
    1,836 on at
    is it possible to ovrride selection chsnge method on extended form
    what does the comtrol name here will contain the name of my field or the combo box , my field which i am going to make enable/disable is real field not string .
    [ExtensionOf(formControlStr(ProjWorkBreakdownStructureV2,controlname ))]
     
  • Verified answer
    Martin Dráb Profile Picture
    237,681 Most Valuable Professional on at
    is it possible to ovrride selection chsnge method on extended form
    Please never describe a problem by mere "it is not working", because that may mean many different things. Instead, tell us what happened.
     
    There are many bugs in your code.

    1. First of all, your code won't even compile. As I told you in your previous thread, you must start by fixing compilation errors.
    2. If it compiled, your code would throw an exception ("Object reference is not set to an instance of object") when calling allowEdit(), because you forgot to put any value to PSAActivityEstimates_ProjectValue variable.
    3. Your code will always set the value to true.
    4. PSAActivityEstimates_ProjectValue sounds like a control bound to a data source field, therefore you should change the property of the data source field and not just of an individual control.

    You could easily identify many of the problems by yourself if you start paying attention to what error messages tell you.
     
    Also, there is a better place for this logic: updateControls() method of ProjWorkBreakdownStructureV2 form. Therefore I suggest something like this:
    [ExtensionOf(formStr(ProjWorkBreakdownStructureV2))]
    internal final class DT_PSAActivityEstimatesDK_Extension
    {
        /// <summary>
        ///     Updates the control visibility and editability.
        /// </summary>
        protected void updateControls()
        {
            next updateControls();
    
            PSAActivityEstimates_ds.object(fieldNum(PSAActivityEstimates, ProjectValue))
                .allowEdit(ViewMode.selection() == ProjWorkBreakdownStructureViewMode::CostEstimates);
        }
    }
    
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    is it possible to ovrride selection chsnge method on extended form
    i have made changes in code , will try to debug it and follow the steps,  martin .

    [ExtensionOf(formControlStr(ProjWorkBreakdownStructureV2, ViewMode))]
    final class DT_PSAActivityEstimatesDK_Extension
    {
        public int selectionChange()
        {
            int ret = next selectionChange();
            FormRealControl   PSAActivityEstimates_ProjectValue;
            FormComboBoxControl   ViewMode;
           
            if (this.selection() == enum2Int(ProjWorkBreakdownStructureViewMode::Scheduling))
            {
                boolean schedulingMode = ViewMode.selection() == enum2int(ProjWorkBreakdownStructureViewMode::Scheduling);
                PSAActivityEstimates_ProjectValue.allowEdit(schedulingMode);
            }
            else if (this.selection() == enum2Int(ProjWorkBreakdownStructureViewMode::CostEstimates))
            {
                PSAActivityEstimates_ProjectValue.allowEdit(true);
            }
            return ret;
               
        }
    }
  • Community member Profile Picture
    4 on at
    Is it possible to override selectionChange method on extended form
    It seems like you are trying to make a field on a form data source non-editable based on the selection made in a combo box. However, you mentioned that the selection change method you wrote is not working. I'll provide some guidance on how to achieve this, but keep in mind that the actual implementation might vary depending on the specific development platform or programming language you are using. I'll assume you are working with a common scenario like a web application using JavaScript/jQuery.
    Here's a general outline of how you can make the field non-editable based on the combo box selection:
    Identify the Field: First, identify the field that you want to make non-editable based on the combo box selection.
    Selection Change Event: Make sure you have a selection change event bound to the combo box. This event will be triggered whenever the user selects a different value from the combo box.
    Read Combo Box Value: In the selection change event handler, read the selected value from the combo box.
    Make Field Non-Editable: Depending on the selected value from the combo box, use JavaScript/jQuery to select the corresponding field on the form data source and set its "readonly" attribute to true or disabled. This will prevent the user from editing the field.
    Handle Default Value: If there is a default value for the combo box, ensure that the corresponding field on the form data source is initially set to either editable or non-editable based on that default value.
  • GirishS Profile Picture
    27,827 Moderator on at
    is it possible to ovrride selection chsnge method on extended form
    I am sorry, I am wrong here you cannot write COC for selection change method. 
    Instead, you can write onSelectionChange event handler for the combo box control.
       
    Thanks,
    Girish S.
     
     
  • Martin Dráb Profile Picture
    237,681 Most Valuable Professional on at
    Is it possible to override selectionChange method on extended form
    Your code is still almost the same. It'll fail because you're calling selection() and allowEdit() on null objects, and it'll always set the value to true (never to false). And in my opinion, it's at a wrong place.
     
    Please try to compile, run and debug your code before posting it here. And if you have a problem, explain it. Just throwing a piece of code here isn't a good approach.

    Also note that I already pointed out to your bugs with empty object variables not just in this one, but also in your previous thread. Please start paying attention the these bugs, so common in your code.
  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at
    Is it possible to override selectionChange method on extended form
    It looks something like below for selectionChange event handler.
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormControlEventHandler(formControlStr(ProjWorkBreakdownStructureV2, ComboBoxControl), FormControlEventType::SelectionChanged)]
        public static void FormComboBoxControlName_OnSelectionChanged(FormControl sender, FormControlEventArgs e)
        {
            FormComboBoxControl check = any2Object(sender) as FormComboBoxControl;
            if(check.valueStr() == "Scheduling")
            {
                FormRun frun = check.formRun();
                FormRealControl realControl = frun.design().controlName("PSAActivityEstimates_ProjectValue");
                realControl.allowEdit(true);
            }
        }
     
    Thanks,
    Girish S.
  • Dineshkarlekar Profile Picture
    1,836 on at
    Is it possible to override selectionChange method on extended form
    hi martin 
    thanks for reply but my form is extended it wont allow me to override updatecontrols method and it is protected so can it be use in my extension class .
     
     
     
     
     

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 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans