Search code examples
axaptamicrosoft-dynamicsx++dynamics-365-operations

D365 Clicked method on command button


In D365 Finance and Operations, on form TaxExempt, General Section, there are several fields like CodeType, CodeName, CompanyList (dropdown menu). User should type in desired values (types and names). In next section Property VAT - setup there is command button New. When clicked on that button, it should create line with values which are taken from General Section: Company(from company list selection), Sales Tax Code (from code type) and Name (from Code Name). For now, it only creates blank line. Is there some advice how this can be performed ?

enter image description here


Solution

  • The method that will accomplish your goal is the initValue on the form datasource. After the super() call, add default values from other fields located on your form. A sample might look like this:

    [DataSource]
    class TaxExemptCodeTable
    {
        /// <summary>
        /// Default values from other form controls/fields on new record creation
        /// </summary>
        public void initValue()
        {
            super();
    
            TaxExemptCodeTable.Value = CustomFormControl.text();
    
            //etc.
        }
    }
    

    If you are creating an extension, there are actually multiple events for this depending on the existing baseline code. OnInitValue would be the analogue to compare to the non-extension solution mentioned above, but if there is existing code on this it might overwrite your field if there is already defaulting logic on the formdatasource. This is because the event will fire as one of the last methods called by the framework in the super() call, but before any code placed after the super(). This complicates the extension scenario.

    If this is the case, you could look into defaulting values on the OnCreated event which will fire after the previous events and "base"/"out of the box code" that might already exist on these methods and/or events. This would overwrite any existing defaulting/init logic with the values you specify in the oncreated event, while also giving you the context of the form to work with (as opposed to table level events which would not have form controls/values to use which seems mandatory for your requirements)

    enter image description here