Wednesday, February 3, 2021

Based on security roles to enable or disable the Fields in a form in D365FO

 Hi guys, Today we see how to Based on security roles to enable or disable the Fields in a form in D365 FO.

Please check below code.

    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated)]

    public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

    {

        securityrole            role;

        securityuserrole        userrole;

        boolean                 check;

        

        select firstonly RecId from role

                    join userrole

                where role.recid == userrole.securityrole

                && role.name== 'Test'

                && userrole.user == curuserid();


        check = (role.recid ? true : false);


        sender.object(fieldNum(SalesTable, TestField)).allowEdit(check);

}


Keep Daxing!!

No comments:

Post a Comment