How to write the standard data entity extension method

 Today we have a requirement to call the modified and other method of the standard data entity while we are going to import So below are the example 


[ExtensionOf(dataentityviewstr(EntAssetMaintenanceWorkOrderTableEntity))]

internal final class IHSEntAssetMaintenanceWorkOrderTableEntity_Extension

{

    



    public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)

    {

        next mapEntityToDataSource(_entityCtx, _dataSourceCtx);


        switch (_dataSourceCtx.name())

        {

            case dataEntityDataSourceStr(EntAssetMaintenanceWorkOrderTableEntity,ENtAssetWorkorderTable):

                if(this.FromFunctionalLocationId)

                {

                    InventLocation warehouse;

                    ENtAssetWorkorderTable request             = _entityCtx.getRuntimeContextByName(dataEntityDataSourceStr(EntAssetMaintenanceWorkOrderTableEntity, ENtAssetWorkorderTable)).getBuffer();

                    EntAssetFunctionalLocation fromFunctionalLocation = EntAssetFunctionalLocation::find(this.FromFunctionalLocationId);


                    request.FromSite = fromFunctionalLocation.InventSiteId;

                    request.FromLocationId = fromFunctionalLocation.InventLocationId;

                    warehouse                              = InventLocation::find(fromFunctionalLocation.InventLocationId);

                    request.FromwMSLocationId              = warehouse.WMSLocationIdDefaultReceipt;

                }

                if(this.ToFunctionalLocationId)

                {

                    InventLocation warehouse;

                    ENtAssetWorkorderTable request             = _entityCtx.getRuntimeContextByName(dataEntityDataSourceStr(EntAssetMaintenanceWorkOrderTableEntity, ENtAssetWorkorderTable)).getBuffer();

                    EntAssetFunctionalLocation ToFunctionalLocation = EntAssetFunctionalLocation::find(this.ToFunctionalLocationId);


                    request.ToSite = ToFunctionalLocation.InventSiteId;

                    request.ToLocationId = ToFunctionalLocation.InventLocationId;

                    warehouse                              = InventLocation::find(ToFunctionalLocation.InventLocationId);

                    request.TowMSLocationId                = warehouse.WMSLocationIdDefaultReceipt;

                }

                break;

        }

    }


    public boolean insertEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)

    {

        if (_dataSourceCtx.name() == dataEntityDataSourceStr(EntAssetMaintenanceWorkOrderTableEntity, IHSEWasteManagement))

        {

            IHSEWasteManagement ewasteManagement = _dataSourceCtx.getBuffer();

            this.ihsEWasteManagementModified(ewasteManagement);

        }



        boolean ret = next insertEntityDataSource(_entityCtx, _dataSourceCtx);

       

        if (_dataSourceCtx.name() == dataEntityDataSourceStr(EntAssetMaintenanceWorkOrderTableEntity, EntAssetWorkOrderTable))

        {

            this.updateIHSDriverMasterDetail(_dataSourceCtx);

           // this.updateIHSAssignedPerson(_dataSourceCtx);

        }

       

        return ret;

    }


    /// <summary>

    /// Updates data entity for data source.

    /// </summary>

    /// <param name = "_entityCtx">The data entity runtime context.</param>

    /// <param name = "_dataSourceCtx">The data entity data source runtime context.</param>

    public boolean updateEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)

    {


        if (_dataSourceCtx.name() == dataEntityDataSourceStr(EntAssetMaintenanceWorkOrderTableEntity, IHSEWasteManagement))

        {

            IHSEWasteManagement ewasteManagement = _dataSourceCtx.getBuffer();

            this.ihsEWasteManagementModified(ewasteManagement);

           

        }


        

        boolean ret = next updateEntityDataSource(_entityCtx, _dataSourceCtx);

       

        if (_dataSourceCtx.name() == dataEntityDataSourceStr(EntAssetMaintenanceWorkOrderTableEntity, EntAssetWorkOrderTable))

        {

           

            this.updateIHSDriverMasterDetail(_dataSourceCtx);

        }


        return ret;

    }


    /// <summary>

    /// update driver name on internal type in work order entity.

    /// </summary>

    /// <param name = "_dataSourceCtx">The data entity data source runtime context.</param>

    private void updateIHSDriverMasterDetail(DataEntityDataSourceRuntimeContext _dataSourceCtx)

    {

        EntAssetWorkOrderTable workOrderTable;

        

        ttsbegin;

        workOrderTable = _dataSourceCtx.getBuffer();


        if (workOrderTable)

        {

            workOrderTable.IHSDriverMaster = IHSDriverMaster::findByDriverDetail(this.IHSInternalDriverName, this.IHSInternalDriverContact).RecId;

            workOrderTable.Update();

        }

        ttscommit;

    }


    /// <summary>

    /// update driver name on internal type in work order entity.

    /// </summary>

    /// <param name = "_dataSourceCtx">The data entity data source runtime context.</param>

    private void updateIHSAssignedPerson(DataEntityDataSourceRuntimeContext _dataSourceCtx)

    {

        EntAssetWorkOrderTable workOrderTable;

        IHSEWasteManagement    ewasteManagement;

        

        ttsbegin;

        workOrderTable = _dataSourceCtx.getBuffer();


        if (workOrderTable)

        {

            ewasteManagement = IHSEWasteManagement::findWorkOrderHeader(workOrderTable.RecId);

            if(ewasteManagement)

            {

            

                ewasteManagement.selectForUpdate(true);

                ewasteManagement.AssignPerson = HcmWorker::findByPerson(DirPartyTable::findByName(this.IHSEWasteAssignPersonName).RecId).RecId;

                ewasteManagement.Update();

               

            }

        }

        ttscommit;

    }


    private void ihsEWasteManagementModified(IHSEWasteManagement ewasteManagement)

    {

        if (this.isFieldModified(fieldNum(EntAssetMaintenanceWorkOrderTableEntity, IHSEWasteAssignPersonName)))

        {

            ewasteManagement.modifiedField(fieldNum(IHSEWasteManagement, AssignPersonName));

        }


        if (this.isFieldModified(fieldNum(EntAssetMaintenanceWorkOrderTableEntity, IHSEWasteVendAccountNum)))

        {

            ewasteManagement.modifiedField(fieldNum(IHSEWasteManagement, VendAccountNum));

        }

    }


}

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