Thursday, January 10, 2013

Ax 2009 Set Child Form access based on caller

 
//The following code is a generic code which can be used in scenario when based on certain condition of in main form, the associated forms should be view only.
Example if the item master is approved then the child forms should be only view only (default setting, transaction text etc) else should work as per standard Ax user permissions.

\Classes\SysSetupFormRun
public void init()
{
    this.AA_setCallerFormAccess();
}


void AA_setCallerFormAccess()
{
    FormDataSource formDataSource,formDataSourceChild;
    Object         formObject;
    Object         caller;
    FormRun        callerForm;
    Common         common;
    int            dsCnt;
    ;

    //info(this.args().menuItemName());    
    if (this.args().menuItemName()  != "InventTxt" &&
        this.args().menuItemName()  != "InventPackagingUnit" &&
        this.args().menuItemName()  != "PriceDiscTable_PricePurch" &&
        this.args().menuItemName()  != "PriceDiscTable_LineDiscPurch" &&
        this.args().menuItemName()  != "PriceDiscTable_MultiLineDiscPurch" &&
        this.args().menuItemName()  != "PriceDiscTable_EndDiscPurch" &&
        this.args().menuItemName()  != "SuppItemTable_Purch"
        )
            return;

    formDataSource = this.objectSet();
    if (formDataSource && 
        formDataSource.formRun().args().menuItemType() == MenuItemtype::Display)
    {
        caller = formDataSource.formRun().args().caller();
        if (!caller)
            return;
            
        callerForm = caller;
        if (callerForm.name() != formstr(InventTable))
            return;

        for (dsCnt =  1; dsCnt <= formDataSource.query().dataSourceCount(); dsCnt++)
        {
            formDataSourceChild = 
                         this.objectSet(formDataSource.query().dataSourceNo(dsCnt).name());
            if (formDataSourceChild)
            {
                formDataSourceChild.allowCreate(false);
                formDataSourceChild.allowDelete(false);
                formDataSourceChild.allowEdit(false);
            }
        }
    }
}