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!!

No comments:

Post a Comment