Create a new validate method on the standard table

 Today we have a requirement to create a new validate method on the standard table level so below are the example


[ExtensionOf(tableStr(EntAssetWorkOrderLifecycleState))]

final class IHSEntAssetWorkOrderLifecycleStateDbt_Extension

{

    /// <summary>

    ///    Checks whether the instal location enable or not.

    /// </summary>

    /// <param name="_custAccount">

    ///    The <c>_custAccount</c> value that specifies the customer account.

    /// </param>

    /// <returns>

    ///    true if the transactions exist for that customer Account; otherwise, false.

    /// </returns>

    static boolean ihsExistAssetLocation(NoYesId _installAssetLocation)

    {

        EntAssetWorkOrderLifecycleState workOrderLifecycleState;


        select firstonly RecId from workOrderLifecycleState

            where workOrderLifecycleState.IHSAutoInstallAssetLocation == _installAssetLocation;


        return (workOrderLifecycleState.RecId != 0);

    }

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

    static boolean ihsExistAuctionPlan(NoYesId _auctionPlan)

    {

        EntAssetWorkOrderLifecycleState workOrderLifecycleState;


        select firstonly RecId from workOrderLifecycleState

            where workOrderLifecycleState.IHSEnableAuctionPlan == _auctionPlan;


        return (workOrderLifecycleState.RecId != 0);

    }

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

    static boolean ihsExistEWasteManagement(NoYesId _ewasteManagement)

    {

        EntAssetWorkOrderLifecycleState workOrderLifecycleState;


        select firstonly RecId from workOrderLifecycleState

            where workOrderLifecycleState.IHSEnableEWasteManagement == _ewasteManagement;


        return (workOrderLifecycleState.RecId != 0);

    }

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

    static EntAssetWorkOrderLifecycleState ihsFindByAssetLocation(NoYesId _installAssetLocation)

    {

        EntAssetWorkOrderLifecycleState workOrderLifecycleState;


        select *  from workOrderLifecycleState

            where workOrderLifecycleState.IHSAutoInstallAssetLocation == _installAssetLocation;


        return workOrderLifecycleState;

    }

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

    static EntAssetWorkOrderLifecycleState ihsFindByAuctionPlan(NoYesId _auctionPlan)

    {

        EntAssetWorkOrderLifecycleState workOrderLifecycleState;


        select *  from workOrderLifecycleState

            where workOrderLifecycleState.IHSEnableAuctionPlan == _auctionPlan;


        return workOrderLifecycleState;

    }

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

    static EntAssetWorkOrderLifecycleState ihsFindByEWasteManagement(NoYesId _ewasteManagement)

    {

        EntAssetWorkOrderLifecycleState workOrderLifecycleState;


        select *  from workOrderLifecycleState

            where workOrderLifecycleState.IHSEnableEWasteManagement == _ewasteManagement;


        return workOrderLifecycleState;

    }

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

    public boolean validateField(FieldId _fieldIdToCheck)

    {

        boolean ret;


        ret = next validateField(_fieldIdToCheck);


        if (ret && _fieldIdToCHeck == fieldNum(EntAssetWorkOrderLifecycleState, IHSAutoInstallAssetLocation) && this.IHSAutoInstallAssetLocation)

        {

            ret = ret && this.ihsValidateWorkOrderId();

        }


        if (ret && _fieldIdToCHeck == fieldNum(EntAssetWorkOrderLifecycleState, IHSEnableAuctionPlan) && this.IHSEnableAuctionPlan)

        {

            ret = ret && this.ihsValidateAuctionPlan();

        }


        if (ret && _fieldIdToCHeck == fieldNum(EntAssetWorkOrderLifecycleState, IHSEnableEWasteManagement) && this.IHSEnableEWasteManagement)

        {

            ret = ret && this.ihsValidateEWasteManagement();

        }


        return ret;

    }

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

    public boolean ihsValidateWorkOrderId()

    {

        boolean                         ret = true;


        if(EntAssetWorkOrderLifecycleState::ihsExistAssetLocation(this.IHSAutoInstallAssetLocation))

        {

            EntAssetWorkOrderLifecycleState EntAssetWorkOrderLifecycleStateloc = EntAssetWorkOrderLifecycleState::ihsFindByAssetLocation(NoYes::Yes);


            ret = checkFailed(strFmt("Parameter already enabled for %1 state", EntAssetWorkOrderLifecycleStateloc.WorkOrderLifecycleStateId));

        }

        return ret;

    }

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

    public boolean ihsValidateAuctionPlan()

    {

        boolean                         ret = true;


        if(EntAssetWorkOrderLifecycleState::ihsExistAuctionPlan(this.IHSEnableAuctionPlan))

        {

            EntAssetWorkOrderLifecycleState EntAssetWorkOrderLifecycleStateloc = EntAssetWorkOrderLifecycleState::ihsFindByAuctionPlan(NoYes::Yes);


            ret = checkFailed(strFmt("Parameter already enabled for %1 state", EntAssetWorkOrderLifecycleStateloc.WorkOrderLifecycleStateId));

        }

        return ret;

    }

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

    public boolean ihsValidateEWasteManagement()

    {

        boolean                         ret = true;


        if(EntAssetWorkOrderLifecycleState::ihsExistEWasteManagement(this.IHSEnableEWasteManagement))

        {

            EntAssetWorkOrderLifecycleState EntAssetWorkOrderLifecycleStateloc = EntAssetWorkOrderLifecycleState::ihsFindByEWasteManagement(NoYes::Yes);


            ret = checkFailed(strFmt("Parameter already enabled for %1 state", EntAssetWorkOrderLifecycleStateloc.WorkOrderLifecycleStateId));

        }

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