Wednesday, November 22, 2017

How to dynamically change the Field properties based on Enum Value using X++

Write the below code in Class declaration :

public class FormRun extends ObjectRun
{
    #AOT
    TreeNode treeMenuItem,treeForm,table;
 }


-------------------------------------------------------------------------------------------------------------------
Write the below code in combo box SelectionChange Method :

public int selectionChange()
{
    int ret;

    ret = super();

    if(this.selection()== Account_Type::Customer)
    {
     treeForm = treeNode::findNode(@"\Data Dictionary\Tables\Esh_Test\Fields\AccountNum\");
     treeForm.AOTsetProperties("Properties\n ExtendedDataType #" + 'CustAccount' + "\n ENDPROPERTIES\n");
     table = treeNode::findNode(@"\Data Dictionary\Tables\Esh_Test");
     treeForm.AOTSave();   
     table.AOTsave();          // To save the table
     Esh_Test_ds.refresh(); // To refresh the changes made in form data source
    }
    else if(this.selection()== Account_Type::Vendor)
    {
     treeForm = treeNode::findNode(@"\Data Dictionary\Tables\Esh_Test\Fields\AccountNum\");
     treeForm.AOTsetProperties("Properties\n ExtendedDataType #" + 'VendAccount' + "\n ENDPROPERTIES\n");
     table = treeNode::findNode(@"\Data Dictionary\Tables\Esh_Test");
     treeForm.AOTSave();   
     table.AOTsave();          // To save the table
     Esh_Test_ds.refresh(); // To refresh the changes made in form data source
    }
 
    return ret;
}

No comments:

Post a Comment

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// &l...