Showing posts with label Event handlers. Show all posts
Showing posts with label Event handlers. Show all posts

Tuesday, April 6, 2021

Override JumpRef method in standard form control in D365FO

 OverRide JumpRef method in standard form cotrol in D365FO.


  • Copy Form 'OnInitialized' Event handler from standard form.

    [FormEventHandler(formStr(SMAParameters), FormEventType::Initialized)]
    public static void SMAParameters_OnInitialized(xFormRun sender, FormEventArgs e)
    {
	var                     overrides   = new TestClass();
	FormStringControl       formControl = sender.design().controlName(formControlStr(SMAParameters, FormControlName));
	
	formControl.registerOverrideMethod(methodStr(FormStringControl, jumpRef), 
                                            methodStr(TestClass, MethodName), overrides);
    }


  • In TestClass  I have created a new method and written the below code.

    public void method(FormControl _formControl)
    {
	// With Filter

	FormRun         formRun;
	Args            args            = new Args();
	FormDataSource  formDataSource  = new FormDataSource();

	args.name(formStr(formName));

	formRun = ClassFactory.formRunClass(args);
	formRun.init();
	
	formDataSource = formRun.dataSource();
	formRun.run();

	formDataSource.filter(fieldNum(TableName, FieldName), "Value");

	formRun.detach();
	
	----------------------------------------------------------------------------------

	// With out Filter
	Args            args            = new Args();
	
	args.record(common);
	
	new MenuFunction(menuitemdisplaystr(menu item name), 
				MenuItemType::Display).run(args);
	--------------------or------------------------------------------
	smmUtility::openMenuItemForm(menuitemDisplayStr(My menu item name), null, _formControl);
    }


Normal jumpref:

    public void jumpRef(FormControl _formControl)
    {
	smmUtility::openMenuItemForm(menuitemDisplayStr(My menu item name), null, this);

	-----------------------or-----------------------------------------------

	new MenuFunction(menuitemdisplaystr(menu item name), 
			MenuItemType::Display).run(args);
    }


Keep Daxing!!


Monday, March 15, 2021

How to disable system defined buttons in standard form of d365?

   How to disable system-defined buttons in the standard form of d365?



Right-click on the button and copy the name.



check the Below code.


    FormCommandButtonControl 	newButton;

    #SysSystemDefinedButtons //- standard macro

    // #SystemDefinedNewButton - button name.

    newButton = sender.control(sender.controlId(#SystemDefinedNewButton)) as FormCommandButtonControl;

    newButton.visible(false);

    // Disable in design
    sender.formRun().design().showNewButton(0);
    this.form().design().showNewButton(0);

Keep Daxing!!


change view mode to edit mode of a form In D365Fo

How to change form view mode to edit mode in D365.


  • To subscribe to view/edit mode switching, use these events:
    • element.viewEditModeHelper().EditModeSwitching
    • element.viewEditModeHelper().EditModeSwitche
  • To query the current view/edit mode, use these events:
    • element.viewEditModeHelper().isInEditMode()
    • element.viewEditModeHelper().IsInViewMode()
  • To trigger view/edit mode switching, use these events:
    • element.viewEditModeHelper().setViewEditMode(ViewEditMode::Edit)

Keep Daxing!!

Monday, January 25, 2021

Access unbound form control on Event Handlers In D365Fo

 Hi guys, Today we how to Access unbound form control  on Event Handlers In D365Fo.


[FormControlEventHandler(formControlStr(SalesTable, Test), FormControlEventType::Clicked)]

    public static void NewBooking_OnClicked(FormControl sender, FormControlEventArgs e)

    {

        NumberSeq           numberSeq;  

        FormRun             form = sender.formRun();//Getting form

        FormStringControl   name= form.design().controlName(formControlStr(SalesTable, Name));//Getting Form control


        numberSeq = NumberSeq::newGetNum(NumberSeqReference::findReference(extendedTypeNum(TestId)));


        name.text(numberSeq.num());

    }


Keep Daxing!!

Monday, December 7, 2020

how to write validateField method in Dynamics AX 7, d365

 

Hi guys, Today we see How to write validateField method in Dynamics AX 7, d365.


Check Below class.


class CustTable_Events

{

// Using On Events

    /// <summary>

    ///

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    [DataEventHandler(tableStr(CustTable), DataEventType::ValidatedField)]

    public static void CustTable_onValidatedField(Common sender, DataEventArgs e)

    {

        ValidateFieldEventArgs event = e as ValidateEventArgs;

        CustTable custTable = sender as CustTable;

    }


// Using Post EventHandler

    /// <summary>

    ///

    /// </summary>

    /// <param name="args"></param>

    [PostHandlerFor(tableStr(CustTable), tableMethodStr(CustTable, validateField))]

    public static void CustTable_Post_validateField(XppPrePostArgs args)

    {

        CustTable custTable     = args.getThis();   //getting table buffer

        FieldId fieldId              = args.getArg("p1"); // Variable buffer

        boolean ret                   = args.getReturnValue(); // get return value from standard method


        switch(fieldId)

        {

            case fieldNum(CustTable, AccountNum):

                if (strLen(custTable.AccountNum) <= 3)

                {

                    ret = ret && checkFailed("Account number should be more than 3 charecters.");

                }

                break;

        }

        args.setReturnValue(ret); // set the return value of this method to standard

    }


Keep Daxing!!

Thursday, December 3, 2020

Change LinkType on FormDatasource in AX7 / D365

 

Hi guys, Today we see how to change LinkType on FormDatasource in AX7 / D365.


In this post I change the link type of salesline Table in SalesTable Form without overlayring.

/// <summary>

/// 

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Initialized)]

public static void SalesLine_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)

{      

    sender.queryBuildDataSource().joinMode(joinMode::OuterJoin); 

}

Keep Daxing!!


Thursday, November 26, 2020

how to get selected records from a form data source using Event handlers of Form in D365/Ax 7.0

 

Hi guys, Today we see how to get selected records from a form data source using Event handlers on Form in D365/Ax 7.0.


Get Current record from form by 'Xformrun':

[formeventhandler(formstr(custgroup), formeventtype::activated)]

    public static void custgroup_onactivated(xformrun sender, formeventargs e)

    {

        custgroup     custgroup;

       // formdatasource ds = sender.datasource(formdatasourcestr(custgroup, custgroup));

       //  custgroup  = ds.cursor();

       //----------OR--------------

       custgroup = sender.datasource(formdatasourcestr(custgroup, custgroup)).cursor();

        info(strfmt('%1', custgroup.custgroup));

    }


Get Current record, FormRun  from form by 'Formdatasource':

[formdatasourceeventhandler(formdatasourcestr(custgroup, custgroup), formdatasourceeventtype::activated)]

    public static void custgroup_onactivated(formdatasource sender, formdatasourceeventargs e)

    {

        custgroup     custgroup;

        // FormRun  formRun = sender.formRun() as FormRun;

        // FormDataSource ds = sender.formrun().datasource('custgroup');

        // ---------------OR------------

        // formdatasource ds = sender.datasource(formdatasourcestr(custgroup, custgroup));

        custgroup = sender.cursor();

       // Button control

       // formRun.design().controlName(formControlStr(Custgroup,Clicked)).enabled(false);

        info(strFmt('%1 - %2 ', custGroup.CustGroup, custGroup.Name));

}


Get Current record from form by 'FormControl' :

[FormControlEventHandler(formControlStr(CustGroup, Clicked), FormControlEventType::Clicked)]

    public static void Clicked_OnClicked(FormControl sender,  FormControlEventArgs e)

    {

       // FormRun  formRun = sender.formRun() as FormRun;

       // formRun.myCustomerMethod();

       CustGroup  custGroup;

       custGroup = sender.formRun().dataSource().cursor();

       info(strFmt('%1 - %2 ', custGroup.CustGroup, custGroup.Name));

    }

Get Current record from form by 'FormDataObject':

{

       CustGroup       custGroup;

        FormDataSource  fds;

        FormDataObject  fd = any2Object(sender) as FormDataObject;

        FormDataSource  fds2 =sender.datasource().formRun().dataSource(2).cursor();

        fds = fd.datasource();

        custGroup = fds.cursor();

        custGroup.Description = custGroup.custGroup +'  '+custGroup.name;

}


Keep Daxing!!