Table levelemodfiied filed COC

 Today we have a requirement to create COC of the modified filed of the standard table So below are the example :- 


[ExtensionOf(tableStr(EntAssetWorkOrderLine))]

final class IHSEntAssetWorkOrderLineDbt_Extension

{

    /// <summary>

    /// Method to display Asset lifestate On Asset.

    /// </summary>

    /// <returns>

    /// The Asset lifestate On Asset.

    /// </returns>

    [SysClientCacheDataMethodAttribute(true)]

    display EntAssetLifecycleStateId displayAssetLifeCycleState()

    {

        EntAssetObjectLifecycleStateRecId lifeCycleStateReciD = this.objectTable().ObjectLifecycleState;//EntAssetObjectTable::ihsFindByAssetAndBarcode(EntAssetObjectTable::findRecId(this.object).ObjectID , this.IHSBarcode).ObjectLifecycleState;

        return EntAssetObjectLifecycleState::find(lifeCycleStateReciD).ObjectLifecycleStateId;

    }

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

    public static EntAssetWorkOrderLine ihsFindByWorkorderRecid(EntAssetWorkOrderRecID _recId, boolean _forUpdate = false)

    {

        EntAssetWorkOrderLine    workOrderLine;

    

        if (_recId)

        {

            workOrderLine.selectForUpdate(_forUpdate);

    

            select firstOnly workOrderLine

                where workOrderLine.WorkOrder == _recId;

        }

    

        return workOrderLine;

    }

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

    // <summary>


    // To modifiedfield call the "avaInitFromWorkOrderType" method to check the works order type


    // </summary>


    public void modifiedField(FieldId _fieldId)

    {

        next modifiedField(_fieldId);


        switch (_fieldId)

        {

            case fieldNum(EntAssetWorkOrderLine,  Object):

                this.ihsInitFromWorkOrderObject();

                // update net value on the work orderline 

                this.ihsUpdateNetValue(this.Object);

                break;


            case fieldNum(EntAssetWorkOrderLine,  IHSAssetCondition):

                this.ihsUpdateAssetLifeCycleState();

                break;

        }

    }

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

    // <summary>

    // Method will check that work order type what is the work order classification selected on work order typr form

    // </summary>


    public void ihsInitFromWorkOrderObject()

    {

        if(!this.RefRecId)

        {

            

            EntAssetObjectTable assetTable = EntAssetObjectTable::findRecId(this.Object);


            this.IHSBarcode = assetTable.IHSBarcode;

            this.IHSName    = assetTable.Name;

            this.IHSItemId  = assetTable.ItemId;

            this.IHSObjectLifecycleState = assetTable.ObjectLifecycleState;

            this.IHSFunctionalLocation  = assetTable.FunctionalLocation;

            this.IHSFunctionalLocationTypeId =this.functionalLocation().functionalLocationType().FunctionalLocationTypeId; //EntAssetFunctionalLocationType::findRecId(EntAssetFunctionalLocation::findRecID(this.FunctionalLocation).FunctionalLocationType).FunctionalLocationTypeId;

            this.IHSObjectTypeID = this.objectTable().objectType().ObjectTypeID; //EntAssetObjectType::find(EntAssetObjectTable::findRecId(this.objectID).ObjectType).ObjectTypeID;


            this.ihsInitFromAttributeTypeId(this.Object);

            this.displayAssetLifeCycleState();

        }

    }

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

    public void ihsUpdateAssetLifeCycleState()

    {

        EntAssetObjectTable assetTable = EntAssetObjectTable::findRecId(this.Object);

       

        ttsbegin;

        assetTable.selectForUpdate(true);

        assetTable.ObjectLifecycleState = IHSWorkOrderAssetStateTable::findByType(this.workOrderTable().workOrderType().WorkOrderTypeId, this.IHSAssetCondition).ObjectLifecycleState;

        assetTable.update();

        ttscommit;

    }

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

    // <summary>

    // Get the asset group from the parameter form..

    // </summary>


    public void ihsInitFromAttributeTypeId(EntAssetObjectRecID _object)

    {

        EntAssetParameters  entAssetParameters = EntAssetParameters::find();

       // EntAssetAttributeTypeId getAssetGroup = entAssetParameters.IHSAttributeTypeId;

        EntAssetObjectAttribute objectbjectAttribute;


        select firstonly objectbjectAttribute

            where objectbjectAttribute.Object == _object

            && objectbjectAttribute.AttributeTypeId == entAssetParameters.IHSAttributeTypeId;


        if(objectbjectAttribute.RecId)

        {

            this.IHSAssetGroup = objectbjectAttribute.ValueString;


        }



    }

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

    public void ihsUpdateNetValue(EntAssetObjectRecID _object)

    {

       

        EntAssetObjectTable     objectTable;

        AssetTable              assetTable;

        EntAssetParameters      parameters  = EntAssetParameters::find();

        AssetBook               assetBook;

        IHSAssetSumCalc         ihsAssetSumTrans;

        int                     currentYear = year(systemDateGet());

        date                    startDate   = mkDate(1, 1, 1900);

        date                    endDate     = mkDate(31, 12, currentYear);

        AmountMST               netValue;


        select objectTable

            where objectTable.RecId == _object

                join assetTable

            where assetTable.AssetId == objectTable.FixedAssetId

                join assetBook

            where assetBook.AssetId == assetTable.AssetId

                && assetBook.BookId == parameters.IHSBookId;

       

            ihsAssetSumTrans = IHSAssetSumCalcTrans::newAssetPeriod(assetBook.AssetId, assetBook.BookId, startDate, endDate);

            netValue = ihsAssetSumTrans.netBookValue();


            this.IHSNetbookValue = netValue;

    }

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

    public void ihsImportFromAssetTable()

    {

        EntAssetObjectTable assetTable = EntAssetObjectTable::ihsFindByBarcode(this.IHSBarcode);


            this.Object     = assetTable.RecId;

            this.IHSName    = assetTable.Name;

            this.IHSItemId  = assetTable.ItemId;

            this.IHSObjectLifecycleState = assetTable.ObjectLifecycleState;

            this.IHSFunctionalLocation  = assetTable.FunctionalLocation;

            this.IHSFunctionalLocationTypeId =this.functionalLocation().functionalLocationType().FunctionalLocationTypeId; //EntAssetFunctionalLocationType::findRecId(EntAssetFunctionalLocation::findRecID(this.FunctionalLocation).FunctionalLocationType).FunctionalLocationTypeId;

            this.IHSObjectTypeID = this.objectTable().objectType().ObjectTypeID; //EntAssetObjectType::find(EntAssetObjectTable::findRecId(this.objectID).ObjectType).ObjectTypeID;


            this.ihsInitFromAttributeTypeId(this.Object);

            this.displayAssetLifeCycleState();

        

    }


}

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


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