Create custom method on the standard form

 Today we can show how you can create a custom method on the form and call on the form any where 

[ExtensionOf(formStr(EntAssetWorkOrderTable))]

Final class IHSEntAssetWorkOrderTableFrm_Extension

{

    public FormRun  ihsGetFormrun;



=======================================================================



    public void ihsEnableDisablePowerApps(FormRun _formRun, FormDataSource _entAssetWorkOrderTableDS)

    {

        EntAssetWorkOrderTable              EntAssetWorkOrderTable    = _entAssetWorkOrderTableDS.cursor();

        boolean                           isPowerApps = EntAssetWorkOrderTable.IsLogistics;



        

       // FormGroupControl    performWorkPlan    = _formRun.design().controlName(formcontrolstr(EntAssetRequestTable, IHSPerformWorkPlanPerformWork)) as FormGroupControl;

        FormTabPageControl  performWorkPlan    = _formRun.design().controlName(formcontrolstr(EntAssetWorkOrderTable, IHSPerformWorkPlanPerformWork)) as FormTabPageControl;

        FormTabPageControl  headerAssetMovement = _formRun.design().controlName(formcontrolstr(EntAssetWorkOrderTable, HeaderAssetMovement)) as FormTabPageControl;

        FormTabPageControl  ihsPerformWorkPlanMaintenance   = _formRun.design().controlName(formcontrolstr(EntAssetWorkOrderTable, IHSPerformWorkPlanMaintenance)) as FormTabPageControl;

        

        performWorkPlan.enabled(isPowerApps);

        headerAssetMovement.allowEdit(isPowerApps);

        ihsPerformWorkPlanMaintenance.enabled(isPowerApps);

        

    }

=======================================================================

    public void ihsEnableDisableAuctionAndEwasteTab(FormRun _formRun, FormDataSource _entAssetWorkOrderTableDS)

    {

        FormTabPageControl  ihsAuctionPlan      = _formRun.design().controlName(formcontrolstr(EntAssetWorkOrderTable, IHSAuctionPlan)) as FormTabPageControl;

        FormTabPageControl  ihsEWasteManagement = _formRun.design().controlName(formcontrolstr(EntAssetWorkOrderTable, IHSEWasteManagement)) as FormTabPageControl;



        EntAssetWorkOrderTable  entAssetWorkOrderTable    = _entAssetWorkOrderTableDS.cursor();

        EntAssetWorkOrderLifecycleState workOrderLifestateId = EntAssetWorkOrderLifecycleState::find(entAssetWorkOrderTable.WorkOrderLifecycleState);



        boolean     enableAuctionPlan =workOrderLifestateId.IHSEnableAuctionPlan == NoYes::Yes;

        boolean     enableEWasteManagement =workOrderLifestateId.IHSEnableEWasteManagement == NoYes::Yes;



        ihsAuctionPlan.enabled(enableAuctionPlan);

        ihsEWasteManagement.enabled(enableEWasteManagement);



    }

=====================================================================

    public void ihsEnableDisableOfferOfferReceived(FormDataSource _auctionPlanDS)

    {

        IHSAuctionPlan              auctionPlan    = _auctionPlanDS.cursor();

        boolean                     offerReceived = auctionPlan.OfferReceived;

        

        _auctionPlanDS.object(fieldNum(IHSAuctionPlan, OfferAccepted)).enabled(offerReceived);



        if(!offerReceived)

        {

            _auctionPlanDS.object(fieldNum(IHSAuctionPlan, OfferAccepted)).setValue(NoYes::No);

            _auctionPlanDS.object(fieldNum(IHSAuctionPlan, CustAccount)).setValue('');

            _auctionPlanDS.object(fieldNum(IHSAuctionPlan, OfferValue)).setValue('');

            _auctionPlanDS.object(fieldNum(IHSAuctionPlan, Address)).setValue('');

        }

       

    }

=========================================================================

    public void ihsEnableDisableOfferAccepted(FormDataSource _auctionPlanDS)

    {

        IHSAuctionPlan              auctionPlan    = _auctionPlanDS.cursor();

        boolean                     offerAccepted  = auctionPlan.OfferAccepted;

        

        _auctionPlanDS.object(fieldNum(IHSAuctionPlan, CustAccount)).enabled(offerAccepted);

        _auctionPlanDS.object(fieldNum(IHSAuctionPlan, OfferValue)).enabled(offerAccepted);

        _auctionPlanDS.object(fieldNum(IHSAuctionPlan, Address)).enabled(offerAccepted);



        if(!offerAccepted)

        {

            _auctionPlanDS.object(fieldNum(IHSAuctionPlan, CustAccount)).setValue('');

            _auctionPlanDS.object(fieldNum(IHSAuctionPlan, OfferValue)).setValue('');

            _auctionPlanDS.object(fieldNum(IHSAuctionPlan, Address)).setValue('');

        }

       

    }

====================================================================

    public void ihsEnableDisableEWasteDatasource(FormDataSource _ewasteManagementDS)

    {

        IHSEWasteManagement         ewasteManagement    = _ewasteManagementDS.cursor();

        boolean                     ewasteInternal      = ewasteManagement.EWaste == EWaste::Internal;

        boolean                     ewasteExternal      = ewasteManagement.EWaste == EWaste::External;

        boolean                     ewasteNone          = ewasteManagement.EWaste == EWaste::None;

        

        _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, AssignPerson)).enabled(ewasteInternal);

        _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, VendAccountNum)).enabled(ewasteExternal);

       

        if(ewasteInternal)

        {

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, VendAccountNum)).setValue('');

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, PurchAgreement)).setValue('');

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, Service)).setValue('');

        }



        if(ewasteExternal)

        {

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, AssignPerson)).setValue('');

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, PurchAgreement)).enabled(false);

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, Service)).enabled(false);

        }



        if(ewasteNone)

        {

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, AssignPerson)).enabled(False);

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, VendAccountNum)).enabled(False);

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, VendName)).enabled(False);

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, PurchAgreement)).enabled(false);

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, Service)).enabled(false);



            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, AssignPerson)).setValue('');

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, VendAccountNum)).setValue('');

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, VendName)).setValue('');

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, PurchAgreement)).setValue('');

            _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, Service)).setValue('');

        }

    }

===================================================================

    public void ihsEnableEwastePurchaseAgreeement(FormDataSource _ewasteManagementDS)

    {

        IHSEWasteManagement     ewasteManagement = _ewasteManagementDS.cursor();

       

        _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, PurchAgreement)).enabled(ewasteManagement.VendAccountNum ? true:false);

        _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, Service)).enabled(False);

        

    }



    public void ihsEnableEwasteService(FormDataSource _ewasteManagementDS)

    {

        IHSEWasteManagement     ewasteManagement = _ewasteManagementDS.cursor();

        

        _ewasteManagementDS.object(fieldNum(IHSEWasteManagement, Service)).enabled(ewasteManagement.PurchAgreement ? true:false);

        

    }

========================================================================

    public void ihsEnableDisableManageLossAndDiscrepancy(FormDataSource _workOrderLineDS)

    {

        EntAssetWorkOrderLine     workorderLine = _workOrderLineDS.cursor();



        if(workorderLine.IHSManageDiscrepency ==  NoYes::No && workorderLine.IHSManageLoss == NoYes::No)

        {

            _workOrderLineDS.object(fieldNum(EntAssetWorkOrderLine, IHSManageDiscrepency)).enabled(true);

            _workOrderLineDS.object(fieldNum(EntAssetWorkOrderLine, IHSManageLoss)).enabled(true);

        }

        else

        {

            _workOrderLineDS.object(fieldNum(EntAssetWorkOrderLine, IHSManageDiscrepency)).enabled(workorderLine.IHSManageDiscrepency ==  NoYes::Yes);

            _workOrderLineDS.object(fieldNum(EntAssetWorkOrderLine, IHSManageLoss)).enabled(workorderLine.IHSManageLoss ==  NoYes::Yes);

        }

        

        

        

    }



}

================================================================================



How to call on the data source or any form level 



[ExtensionOf(FormDataSourceStr(EntAssetWorkOrderTable, WorkOrderTable))]

final class IHS_EntAssetWorkOrderTable_WorkOrderTable_Frm_Datasrc_Extension

{

    public int active()

    {

        int ret = next active();



        FormRun                 formRun                     = this.FormRun();

        FormDataSource          entAssetWorkOrderTable_DS   = formRun.datasource(FormDatasourceStr(EntAssetWorkOrderTable, WorkOrderTable));

        EntAssetWorkOrderTable  entAssetWorkOrderTable      = entAssetWorkOrderTable_DS.cursor();

        IHSDriverMaster         driverMaster;



        FormTabPageControl      workPlanMaintenance         = this.formRun().design().controlName(formControlStr(EntAssetWorkOrderTable, IHSPerformWorkPlanMaintenance));

        FormTabPageControl      workPlanPerformWork         = this.formRun().design().controlName(formControlStr(EntAssetWorkOrderTable, IHSPerformWorkPlanPerformWork));



        //workPlanMaintenance.visible(entAssetWorkOrderTable.IHSIsMaterialMovement == NoYes::Yes);

        //workPlanPerformWork.visible(entAssetWorkOrderTable.IHSIsPerformWork == NoYes::Yes);

        element.ihsGetFormrun = this.FormRun();

        element.ihsEnableDisablePowerApps(formRun, EntAssetWorkOrderTable_DS);

        element.ihsEnableDisableAuctionAndEwasteTab(formRun, EntAssetWorkOrderTable_DS);



        if(entAssetWorkOrderTable.IHSLogisticsPlanIntExt == IHSLogisticsPlanIntExt::External)

        {

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccount)).enabled(true);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreement)).enabled(true);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSService)).enabled(true);



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverName)).visible(true);

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverContact)).visible(true);



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverMaster)).visible(false);

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSInternalDriverContact)).visible(false);



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverMaster)).setValue('');

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSInternalDriverContact)).setValue('');

        }

        else if(entAssetWorkOrderTable.IHSLogisticsPlanIntExt == IHSLogisticsPlanIntExt::Internal)

        {

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccount)).enabled(false);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreement)).enabled(false);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSService)).enabled(false);



            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccount)).setValue('');

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreement)).setValue('');

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSService)).setValue('');



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverMaster)).visible(true);

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSInternalDriverContact)).visible(true);



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverName)).visible(false);

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverContact)).visible(false);



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverName)).setValue('');

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverContact)).setValue('');

        }

        else

        {

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccount)).enabled(false);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreement)).enabled(false);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSService)).enabled(false);



            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccount)).setValue('');

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreement)).setValue('');

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSService)).setValue('');



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverName)).visible(true);

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverContact)).visible(true);



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverMaster)).visible(false);

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSInternalDriverContact)).visible(false);



            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSDriverMaster)).setValue('');

            entAssetWorkOrderTable_ds.object(fieldNum(EntAssetWorkOrderTable, IHSInternalDriverContact)).setValue('');

        }



        if(entAssetWorkOrderTable.IHSLogisticsPlanIntPerformWork == IHSLogisticsPlanIntExt::External)

        {

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccountPerformWork)).enabled(true);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreementPerformWork)).enabled(true);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSServicePerformWork)).enabled(true);

        }

        else if(entAssetWorkOrderTable.IHSLogisticsPlanIntPerformWork == IHSLogisticsPlanIntExt::Internal)

        {

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccountPerformWork)).enabled(false);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreementPerformWork)).enabled(false);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSServicePerformWork)).enabled(false);



            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccountPerformWork)).setValue('');

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreementPerformWork)).setValue('');

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSServicePerformWork)).setValue('');

        }

        else

        {            

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccountPerformWork)).enabled(false);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreementPerformWork)).enabled(false);

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSServicePerformWork)).enabled(false);



            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSVendAccountPerformWork)).setValue('');

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSPurchAgreementPerformWork)).setValue('');

            entAssetWorkOrderTable_DS.object(fieldNum(EntAssetWorkOrderTable, IHSServicePerformWork)).setValue('');

        }



        driverMaster = IHSDriverMaster::findRecId(entAssetWorkOrderTable.IHSDriverMaster);



        entAssetWorkOrderTable.IHSInternalDriverContact = driverMaster.InternalDriverContact;



        

        return ret;

    }



}



========================================================================================

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++