Thursday, June 30, 2022

Multi select Lookup method for string fields D365 FO

Both the code is written on form datasource level

 //Query                   query = new Query();

                //QueryBuildDataSource    queryBuildDataSource;

                //SysTableLookup          sysTableLookup;

                //sysTableLookup = SysTableLookup::newParameters(tableNum(EcoResProductCategory), _formControl);

                //queryBuildDataSource = query.addDataSource(tableNum(EcoResProductCategory));

                //sysTableLookup.addLookupField(fieldNum(EcoResProductCategory, Category));

                //sysTableLookup.addLookupField(fieldNum(EcoResProductCategory, CategoryHierarchy));

                //sysTableLookup.parmQuery(query);

                //sysTableLookup.performFormLookup();






Query                   query = new Query();

                var selectField = [tableNum(EcoResProductCategory), fieldNum(EcoResProductCategory, Category)];

                QueryBuildDataSource    queryBuildDataSource;

                SysTableLookup          sysTableLookup;

                sysTableLookup = SysTableLookup::newParameters(tableNum(EcoResProductCategory), _formControl);

                queryBuildDataSource = query.addDataSource(tableNum(EcoResProductCategory));

                queryBuildDataSource.addSelectionField(fieldNum(EcoResProductCategory, Category));

                var lookup =  MCOSysMultiselectionLookup::lookup(Query, selectField, MCOSAtoPO_Category,MCOSAtoPO_Category,

                                                                        MCOSAtoPO_Category,MCOSAtoPO_Category.valueStr());

                MCOSAtoPO.Category = lookup.getSelectedStringsJoined();








For Standard form


class MCOSAtoPOFormEventHandler

{

    [FormControlEventHandler(formControlStr(MCOSAtoPO, MCOSAtoPO_MCOSeasonCode), FormControlEventType::Lookup)]

    public static void MCOSAtoPO_MCOSeasonCode_OnLookup(FormControl sender, FormControlEventArgs e)

    {

        FormDataSource fds;

        MCOSAtoPO rTable;

        FormStringControl strControl = sender as FormStringControl ;

        fds = sender.formRun().dataSource("MCOSAtoPO");

        rTable = fds.cursor();

        Query lookupQuery = new Query();

        var selectField = [tableNum(RetailSeasonTable), fieldNum(RetailSeasonTable, seasonCode)];

        QueryBuildDataSource qbds = lookupQuery.addDataSource(tableNum(RetailSeasonTable));

        qbds.addSelectionField(fieldNum(RetailSeasonTable, seasonCode));

        qbds.addSelectionField(fieldNum(RetailSeasonTable, Description));

        qbds.addSelectionField(fieldNum(RetailSeasonTable, StartDate));

        qbds.addSelectionField(fieldNum(RetailSeasonTable, EndDate));

        var lookup =  MCOSysMultiselectionLookup::lookup(lookupQuery, selectField, strControl,strControl,strControl,strControl.valueStr());

        rTable.MCOSeasonCode = lookup.getSelectedStringsJoined();

    }


}

Sunday, June 26, 2022

How to get element from formRun Dynamics 365 FO

[FormControlEventHandler(formControlStr(SalesAgreementListPage, MCOSAtoPO), FormControlEventType::Clicked)]

public static void MCOSAtoPO_OnClicked(FormControl sender, FormControlEventArgs e)

    {

        FormRun                 element             = sender.formRun();

        FormDataSource          SalesAgreementHeader_DS    = element.dataSource(formDataSourceStr(SalesAgreementListPage, SalesAgreementHeader));

        SalesAgreementHeader    SalesAgreementHeader = SalesAgreementHeader_ds.cursor();

        SysGlobalCache globalCache;

        globalCache = ClassFactory.globalCache();

        globalCache.set(strFmt("%1%2",curUserId(),"SalesAgreementHeader"), 0, SalesAgreementHeader.RecId);

    }


Tuesday, June 21, 2022

Error while checking in the code in Visual studio

Error (One or more checked work items failed the transition testing due to invalid field values. Please correct the values and retry the check-in) while checking in the code in Visual Studio


While checking in the code change the related work item as associate instead of resolve from the visual studio as shown below.




Also to resolve this permanently you can change the visual studio settings as per your needs




Monday, June 20, 2022

LCS Error while deploying could hosted dev server

LIFECYCLE SERVICES CANNOT PERFORM THE CURRENT 0 OPERATION. RECEIVED NULL OR EMPTY VALUE FOR PARAMETER 1 WHEN ATTEMPTING TO DEPLOY CLOUD-HOSTED ENVIRONMENTS WITHIN LCS Dynamics 365 FO


Accessing LCS with an account in a different AAD domain than the Azure subscription tenant will cause this issue.

To solve this issue, use an administrator account of the same AAD Domain of the Azure subscription tenant.


Link

Interfaces in Dynamics 365 FO

Interfaces Overview in AX 2012

You create an interface under the Classes node of the AOT. Defining an interface is similar to creating a new class. An interface definition has two components: the declaration and the body.

X++

interfaceDeclaration

{

    #interfaceBody

}


The interface declaration declares various attributes about the interface, such as its name and whether it extends another interface. The interface body contains the method declarations within the interface as shown in the following example.


X++

interface SysDeleteTables

{

    public void doDeleteCustomerTables();

}





Using an Interface

To use an interface, write a class that implements the interface. When a class implements an interface, the class must provide a method implementation for all of the methods declared within the interface as shown in the following example.

class SysDataImport extends SysDataExpImp implements sysDeleteTables

{

// Supply implementation of methods in the interface.

void doDeleteCustomerTables()

{

// Implement the method.

}

}

A class that implements an interface inherits all the method declarations in that interface. However, the class needs to provide bodies for those methods.





Example of Interface

interface IDrivable

{

    int getSpeed()

    {

    }


    void setSpeed(int newSpeed)

    {

    }

}


class Automobile implements IDrivable

{

    int speed;


    public int getSpeed()

    {

        return speed;

    }


    public void setSpeed(int newSpeed)

    {

        speed = newSpeed;

    }

}


class UseAnAutomobile

{

    void DriveAutomobile()

    {

        IDrivable drivable;

        Automobile myAutomobile = new Automobile();

        str temp;


        myAutomobile = new Automobile();


        if (myAutomobile is IDrivable)

        {

            drivable = myAutomobile;

            drivable.setSpeed(42);

            temp = int2str(drivable.getSpeed());

        }

        else

        {

            temp = "Instance is not an IDrivable.";

        }


        info(temp);

    }

}


Link

PostLoad() method in AX tables Dynamics 365 FO

PostLoad() is the method that is used to read records from the database and you can perform any custom logic by overriding this method on any table.


public void postLoad()

{

    super();


    if (this.Name == 'MEL')

        this.Value = 5;

}

Thursday, June 16, 2022

Getting an error while performing Get Latest Version in Visual studio in Dynamics 365 FO

 Error message:

Multiple errors occurred during the operations, the first of which is displayed below. A full error list is available in the Output Window. Access is denied.





Finally, stopping AOS services (IIS) and world wide services, and W3C in the development machine and performing “Get latest version” worked for me. However, I’m not sure of the root cause of the issue, but I assume some of the objects are not allowed to overwrite when they are in use.

Wednesday, June 15, 2022

How to setup ADO in Dynamics 365 FO

Open Visual studio

Look for the "Team explorer - connect" tab

then click on connect 


You will see something like below


Click on Connect button for "Azure DevOps", A new pop-up will come like below


Now add a Microsoft account and you will see the list of organizations you have access to


Select your organization and click connect

Now create a folder hierarchy like below
    * Trunk
         * Dev
                * Projects
         * Main
                * Projects


Now click on advanced, and a new pop-up window will show


Now fill in the details as filled in the picture below


Press ok and now a new popup will show as shown below


Click Yes, Now the model/models will be downloaded

Now build the models and synchronize DB, restart the server



Wednesday, June 1, 2022

Intelli sense in VS

How to turn on/Trigger Intelli Sense in Visual Studio in Dynamics 365 FO


Intelli sense


What is Intelli sense?

IntelliSense in Visual Studio is a feature that helps programmers write code faster and with fewer mistakes. Here's how it simplifies coding:


1. Auto-completion: 

It suggests how to finish lines as you type, so you don't have to type everything.


2. Helps with errors: 

It points out mistakes as you go, helping you fix them right away.


3. Shows useful info: 

It gives quick pop-ups with info about codes, like what a function does or what parameters it needs.


4. Easy to use: 

It lists options you can use in your code, making it easier to remember what commands are available.


Overall, IntelliSense is like a smart assistant that helps you code by giving hints and fixing mistakes along the way.



How to turn on/trigger Intelli sense?

Open visual studio, go to any code

and press Ctrl + Space