Wednesday, August 10, 2022

Confirmation of sales agreement by code in Dynamics 365 FO

class SalesAgreementConfirm

{

    public static void run()

    {

        SalesAgreementHeader    SalesAgreementHeader;

        AgreementConfirm_Sales  objAgreementConfirm_Sales;

        SalesAgreementHeader.clear();

        SalesAgreementHeader  = SalesAgreementHeader::findAgreementId('SAG-000002');

        objAgreementConfirm_Sales = AgreementConfirm_Sales::construct();

        objAgreementConfirm_Sales.parmAgreementHeader(SalesAgreementHeader);

        //objAgreementConfirm_Sales.prompt(); //if you want prompt for user

        objAgreementConfirm_Sales.startConfirm(); //if you want silent confirmation without prompt

        info("Confirmed");

    }

}

Tuesday, August 9, 2022

Auto refresh A form when B(Dialog) form is closed

 In form A create a method as below


[ExtensionOf(formStr(SalesLineOpenOrder))]

final class MCOSalesLineOpenOrder_Extension

{

    public void RefreshSalesLine()

    {

        SalesLine_DS.research();

    }

}



On closing of form B write the following method :

public void close()

{

        super();

        if(formHasMethod(element.args().caller(), identifierstr(RefreshSalesLine)))

        {

            FormRun formRunObject;

            formRunObject = element.args().caller();

            formRunObject.RefreshSalesLine();

        }

}

Sunday, August 7, 2022

Data entity method mapEntityToDataSource in dynamics 365 FO

public void mapEntityToDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)

{

        this.skipDataSourceValidateField(fieldNum(InventInventoryMovementJournalEntryV4Entity,JournalNumber), true);

        this.skipDataSourceValidateField(fieldNum(InventInventoryMovementJournalEntryV4Entity,LineNumber), true);

        super(_entityCtx, _dataSourceCtx);

        switch (_dataSourceCtx.name())

        {

            case dataEntityDataSourceStr(InventInventoryMovementJournalEntryV4Entity,InventJournalTable):

                switch (_entityCtx.getDatabaseOperation())

                    {

                        case DataEntityDatabaseOperation::Insert:

                            InventJournalTable inventJournalTable = _dataSourceCtx.getBuffer();

                            inventJournalTable.initFromInventJournalName(InventJournalName::find(this.JournalNameId));

                            _dataSourceCtx.setBuffer(inventJournalTable);

                            break;

                    }

                    break;

        }

    }

Thursday, August 4, 2022

Get source record from a caller object

Suppose you have a form A that calls form B.

In Form B you want to know what is the data source of Form A and if it’s a VendTable you wish to retrieve the AccountNum field


VendTable vendTableLocal;

switch (element.args().record().dataSource().Name())

        {

            case 'VendTable':

                vendTableLocal = element.args().record() as VendTable;

                    break;

            default:

                break;

        }

Link

Monday, August 1, 2022

Relation between EcoResCategory and ItemId

ItemId itemId = "ITEMNO-000000572";

EcoResProductCategory EcoResProductCategory;

EcoResCategory EcoResCategory;

EcoResProduct EcoResProduct;

InventTable InventTable;

;

select EcoResCategory

join EcoResProductCategory

join EcoResProduct

join InventTable

where EcoResCategory.RecId == EcoResProductCategory.Category

&& EcoResProduct.RecId == EcoResProductCategory.Product

&& EcoResProduct.RecId == InventTable.Product

&& InventTable.ItemId== ItemId ;


info(strFmt("%1",EcoResCategory.Name));