Sam's Microsoft Dynamics 365 Blog

Tuesday, 10 September 2019

Using ExecuteMultiple and Upsert Request in C#

ExecuteMultiple in Dynamics 365 is used to execute multiple requests, at the same time.  

In Dynamics 365, we can insert or update request in a single request that is called Upsert. 




Now here we are using a scenario for applying ExecuteMultiple and Upsert Request in a single request.

Here I have created a key inside Contact entity with the name  ”sam_myerpid”. I have mapped ”sam_myerpid” with “ContactId”.

Code:

            ///Creating a list
            List<Customer> customers = new List<Customer>();

            customers.Add(new Customer() { id = 1, firstname = "Sam", lastname = "Khan" });
            customers.Add(new Customer() { id = 2, firstname = "Michel", lastname = "Andrew" });
            customers.Add(new Customer() { id = 3, firstname = "Robert", lastname = "Grew" });

            ///Define ExecuteMultipleRequest
            ExecuteMultipleRequest multipleRequest = new ExecuteMultipleRequest()
            {
                Settings = new ExecuteMultipleSettings()
                {
                    ContinueOnError = true,
                    ReturnResponses = true
                },
                Requests = new OrganizationRequestCollection()
            };
            
            foreach (var cust in customers)
            {
                //Define and add value to KeyAttributeCollection
                KeyAttributeCollection keyColl = new KeyAttributeCollection();
                keyColl.Add("sam_myerpid", cust.id.ToString());

                ///Define Entity and pass KeyAttributeCollection
                Entity custEntity = new Entity("contact", keyColl);

                ///Map fields data
                custEntity.Attributes["firstname"] = cust.firstname;
                custEntity.Attributes["lastname"] = cust.lastname;

                ///Define UpsertRequest
                UpsertRequest req = new UpsertRequest()
                {
                    Target = custEntity
                };

                ///Add UpsertRequest to ExecuteMultipleRequest
                multipleRequest.Requests.Add(req);
            }

            ///Execute
            ExecuteMultipleResponse multipleResponse = (ExecuteMultipleResponse)service.Execute(multipleRequest);


Screenshot: -


So now after execute, this request It will insert records and if there are already records with same ”sam_myerpid” then it will update that records.

  Thanks for reading the article. Hope this Article will helpful for you. Cheers!!!

Source: - 


Monday, 5 August 2019

Create an Environment in Dynamics 365


1. Open and Sign in to the Admin center at  https://admin.powerapps.com/

2. In the navigation pane, click on Environments.


3.  Now click on New environment.

4. In the New environment dialog box, enter the name for the environment, Select a region and environment type from the drop-down lists.


Note: We can’t change the region once the environment is created.

5. Now click on Create environment.


6. Once the environment is created, a new dialog box will appear, and it will be prompted to create a database. Click on Create database to enable access to the Common Data Service.


7. Select the currency and language for the data stored in the database.


Note: -We can’t change the currency or language once the database is created.

8. Now it may take several minutes to create the database. After the database is created, the new environment appears in the list of environments on the Environments page.





  Thanks for reading the article. Hope this Article will helpful for you. Cheers!!!

Source:- https://docs.microsoft.com/en-us/power-platform/admin/create-environment

How to Get the Power Automate Flow Run URL Using Expressions

In many Power Automate projects, especially those involving approvals, error handling, or audit logs, it’s helpful to have a direct link to ...