Friday, December 15, 2023

How to pass Arguments/records in RDP Report through form or how to open report from the Form using controller class X++ in Dynamics 365 FO

Pass arguments in RDP Report through form in D365 FO on Dynamicscommunity101


How to pass Arguments/records in RDP Report through form, how to open report from the Form using controller class X++ in Dynamics 365 FO

Dynamics 365 FO Opening Dialogue form through X++

Dynamics 365 FO Opening Dialogue form through X++

Dynamics 365 X++ OData Actions

Dynamics 365 X++ OData Actions

Enable Power Platform Integration

Enable Power Platform Integration

File based integration(Import) using Logic apps -D365 FO Enqueue Dequeue

File based integration(Import) using Logic apps -D365 FO

Selection changed and active method in Dynamics 365 FO

1. Selection Changed Method:

   - This method is triggered when the selection of a record in a grid or a form changes.

   - It is commonly used to handle scenarios where actions need to be taken based on the user's selection of a record. For example, enabling or disabling buttons, displaying additional details of the selected record in another form part, or refreshing data based on the new selection.

   - The Selection Changed method is associated with the form's data source and is typically overridden in the form's data source class.


2. Active Method:

   - The Active method is called whenever a record in a form is activated or when the focus is set on a record.

   - It's used to perform actions every time a record becomes active, which might not necessarily be due to a change in selection. For example, it can be used to display additional details of the record or to execute some logic related to the active record.

   - This method is also associated with the form's data source and can be overridden to provide custom logic whenever a record becomes active in the form.


In essence, while the "Selection Changed" method is specifically about the change in the selection of records, the "Active" method is more about a record gaining focus or becoming the currently active record, regardless of whether it was selected previously or not. Both are important in managing the behavior and interaction of forms in Dynamics 365 F&O.

Dynamics 365 FO code to generate access token and parse the JSON response using contract class to get the access token

1. Class LSGenerateToken :


using System.Net.Http;

using System.Text;

internal final class LSGenerateToken

{

    public static void main(Args _args)

    {

        str responseJson;

        HttpClient httpClient = new HttpClient();

        str requestUrl = 'https://login.microsoftonline.com/TENANTID/oauth2/token';

        str body = strFmt("grant_type=client_credentials&client_id=%1&client_secret=%2",

        'XXXXXXXXXXXXXXXXX','YYYYYYYYYYYYYYYYYYYYY');

        // Send the request and get the response

        HttpResponseMessage response = httpClient.PostAsync(requestUrl, new StringContent(body, Encoding::UTF8, "application/x-www-form-urlencoded")).Result;

        str responseBodyStr;

        if (response.IsSuccessStatusCode)

        {

            // Parse the response body

            var responseBody = response.Content.ReadAsStringAsync().Result;

            responseBodyStr = responseBody;

        }

        else

        {

            // Handle error

            throw error(strFmt("Failed to get access token. Status code: %1", response.StatusCode));

        }    


        LSAccessTokenContract _Contract = FormJsonSerializer::deserializeObject(classNum(LSAccessTokenContract), responseBodyStr);

        info(strfmt("Access token = %1",_Contract.parmaccess_token()));

    }


}






2. LSAccessTokenContract :

[DataContract]

class LSAccessTokenContract

{

    str token_type;

    str expires_in;

    str ext_expires_in;

    str expires_on;

    str not_before;

    str resource;

    str access_token;


    [DataMember("token_type")]

    public str parmtoken_type(str _token_type = token_type)

    {

        token_type = _token_type;

        return token_type;

    }


    [DataMember("expires_in")]

    public str parmexpires_in(str _expires_in = expires_in)

    {

        expires_in = _expires_in;

        return expires_in;

    }


    [DataMember("ext_expires_in")]

    public str parmext_expires_in(str _ext_expires_in = ext_expires_in)

    {

        ext_expires_in = _ext_expires_in;

        return ext_expires_in;

    }


    [DataMember("expires_on")]

    public str parmexpires_on(str _expires_on = expires_on)

    {

        expires_on = _expires_on;

        return expires_on;

    }


    [DataMember("not_before")]

    public str parmnot_before(str _not_before = not_before)

    {

        not_before = _not_before;

        return not_before;

    }


    [DataMember("resource")]

    public str parmresource(str _resource = resource)

    {

        resource = _resource;

        return resource;

    }


    [DataMember("access_token")]

    public str parmaccess_token(str _access_token = access_token)

    {

        access_token = _access_token;

        return access_token;

    }


}



Thursday, December 14, 2023

Mastering Transaction Control in Dynamics 365 FO Understanding ttsBegin ttsCommit and ttsAbort


In Microsoft Dynamics 365 for Finance and Operations, which is built on the X++ programming language, ttsBegin, ttsCommit, and ttsAbort are commands used to manage database transactions. These commands ensure data integrity and consistency during database operations. 

1. ttsBegin: This command starts a database transaction. When you execute ttsBegin, it tells the system that you are starting a series of operations that should be treated as a single unit. If any operation within this unit fails, the entire set of operations should be rolled back to maintain data integrity.

2. ttsCommit: This command is used to commit the transaction. It signals the successful completion of all operations within the transaction started by ttsBegin. When ttsCommit is executed, all changes made to the database within the transaction are permanently saved.

3. ttsAbort: This command is used to abort the transaction. It's invoked when an error occurs or when there's a need to undo the operations performed after ttsBegin. Executing ttsAbort rolls back all changes made during the transaction, restoring the database to its state before ttsBegin was executed.

Transaction Levels:

- Dynamics 365 F&O supports nested transactions. This means you can have multiple levels of ttsBegin commands. 
- Each ttsBegin must have a corresponding ttsCommit or ttsAbort. 
- The system keeps track of transaction levels. A ttsCommit only decreases the transaction level by one. The transaction is only committed to the database when the outermost ttsCommit (when the transaction level reaches zero) is executed.
- If a ttsAbort is executed at any level, all changes in the current transaction level and any nested levels are rolled back.

Example:

Imagine you are updating customer data in a transaction. The code structure would look like this:

x++
ttsBegin;  // Start the transaction
try
{
    custTable.Name = "Customer Name";
    custTable.update();
    ttsCommit;  // Commit the transaction
}
catch
{
    ttsAbort;  // Abort the transaction if an error occurs
}


In this example, if the customer update fails, the ttsAbort in the catch block will be triggered, rolling back both updates to maintain data consistency.

If you've made it this far, please leave a kind word. Your encouragement fuels my desire to produce and share even more valuable content.

Thursday, December 7, 2023

Relationship type property while creating relation in Dynamics 365 FO

In Dynamics 365 Finance and Operations (F&O), the following are the types of relationships between entities:


Association: An association is a relationship between two or more entities where they are linked together based on some common attribute or characteristic. For example, When a customer places an order, there is an association between the customer entity and the order entity, linked by a unique customer ID.

Composition: Composition is a type of association where the entities are dependent on each other, and the child entity cannot exist without the parent entity. For example, A customer profile may be composed of multiple sub-entities like billing addresses, shipping addresses, and payment methods. These sub-entities cannot exist without the customer profile.

Link: A link is a type of association that defines a connection between two entities but does not imply any dependency or ownership. For example, The customer entity could be linked to a loyalty program entity, indicating that this customer is a part of a specific loyalty program but not dependent on it.

Specialization: Specialization is a relationship between entities where one entity is a more specific version of another entity. For example, Customers can be specialized into different types such as "retail customer," "wholesale customer," or "online customer."

Aggregation: Aggregation is a relationship between entities where one entity is composed of or made up of other entities. For example, A household may aggregate multiple individual customer accounts under one umbrella, like a family account.


If you've made it this far, please leave a kind word. Your encouragement fuels my desire to produce and share even more valuable content.

Wednesday, December 6, 2023

Maps and MapEnumerator in Dynamics 365 FO


In Dynamics 365 Finance & Operations (F&O), a "map" is used for organizing and storing data.

Unique Keys: Just like each word in a dictionary is unique, each 'key' in a map is unique. A key is a label or identifier you use to find a specific piece of data (like a word in a dictionary helps you find its definition).

Data Types: The keys and the data (values) they point to can be of any type. For example, a key could be a number, and the value could be a name or a date.

Efficiency: Maps are designed to let you quickly find data. If you know the key, you can immediately find the value.

Usage: In Dynamics 365 F&O, maps are used to customize how the system works or to connect it with other systems. They help manage and access data in a way that’s easy to understand and use.

In short, maps in Dynamics 365 F&O are like sophisticated dictionaries for storing and finding data, making it easier to manage and use information in the system.


Example:

public static void MapUsage(Args _args)
{
    Map empMap = new Map(Types::Integer, Types::String);

    // Adding values to the map
    empMap.insert(1001, "Atul Yadav");
    empMap.insert(1002, "Joris");

    // Retrieving a value using a key
    info(strFmt("Employee Name: %1", empMap.lookup(1002)));

    // Iterating through the map
    MapEnumerator mapEnumerator = empMap.getEnumerator();
    while (mapEnumerator.moveNext())
    {
        int empId = mapEnumerator.currentKey();
        str empName = mapEnumerator.currentValue();
        info(strFmt("Employee ID: %1, Name: %2", empId, empName));
    }
}


If you've made it this far, please leave a kind word. Your encouragement fuels my desire to produce and share even more valuable content.