Monday, February 3, 2025

Push Multiple Records in a Single Http Request Using Batch API in Logic Apps

 Pushing Multiple Records in a Single Request Using Batch API in Logic Apps:

        We can perform the multiple operations in single request by using Batch API. To know more Click Here

Please follow the below steps:

  • I have added the HTTP request.
  • I configured the following URL and headers.
    Content-Type: multipart/mixed; boundary=batch_CR


  • I used the batch number as batch_CR and the change set number as changeset_EE.
  • I am performing three operations:
    • Creating a record in the vendgroup table.
    • Updating a record in the custgroup table.
    • Deleting a record in the vendgroup table
      --batch_CR
      Content-Type: multipart/mixed; boundary=changeset_EE
      
      --changeset_EE
      Content-Type: application/http
      Content-Transfer-Encoding: binary
      Content-ID: 1
      
      POST VendorGroups?cross-company=true HTTP/1.1
      Content-Type: application/json; type=entry
      
      {
          "dataAreaId": "USMF",
          "VendorGroupId": "Test04",
          "Description": "Test 4",
      }
      
      --changeset_EE
      Content-Type: application/http
      Content-Transfer-Encoding: binary
      Content-ID: 2
      
      PATCH CustomerGroups(dataAreaId='USMF',CustomerGroupId= 'TestC01')?Cross-company=true HTTP/1.1
      Content-Type: application/json; type=entry { "Description": "Test C1111" } --changeset_EE Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 3 DELETE VendorGroups(dataAreaId='USMF',VendorGroupId= 'Test03')?Cross-company=true HTTP/1.1 Content-Type: application/json; type=entry --changeset_EE-- --batch_CR--
  • I used OAuth authentication, providing the Client ID, Secret, and Tenant ID.

Output:

 

If the Batch API request Succeeds:

  1. It returns a 201 status code for the create operation, along with the entire payload of the first request.


  2. It returns a 204 status code for the update and delete operations, as no content is returned after an update and delete.

 

If the Batch API request Fails:

  • The main status code is 200, but within the response body, it returns a 500 error.
  • Below is the output of the Batch API request, with error message highlighted in a green box.

Fetching the Error Message:

  • I added conditions to handle both success and failure cases.

  • If the Batch API request fails, I retrieve the error message using the following expression.
    • Fetch the error
      body('Batch_API')['$multipart'][0]['body']['$multipart'][0]['body']['$applicationHttp']['body']['error']
    • Fetch the error status code
      body('Batch_API')['$multipart'][0]['body']['$multipart'][0]['body']['$applicationHttp']['statusCode']

 

  • If the Batch API request succeeds, I extract the status code using the appropriate expression.
    • Fetch the body
      body('Batch_API')['$multipart'][0]['body']['$multipart'][0]['body']['$applicationHttp']['body']
    • Fetch the status code
      body('Batch_API')['$multipart'][0]['body']['$multipart'][0]['body']['$applicationHttp']['statusCode']



Keep Daxing!!

Monday, January 27, 2025

How to connect UAT data base from dev in D365FO.

How to connect UAT data base(Tier 2) in dev in D365FO.

By default you can connect up to 8 hours after that you have to follow the same process.



1. Log in to LCS and open the UAT environment. Scroll down to find the database account section.

2. Select write ax, provide a description, and click on Request access.


3. Perform a hard refresh, and you should see the following details: Server, Database, User, Password. 

   ServerName/DatabaseName

 

 4. Click on Maintain and select Enable Access.

    

5. Search for "What is my IP" in your dev environment's browser. 

6. Click on Add, then input your IP address and give it a name.

7. Open the K drive and navigate to the AoSService\WebRoot folder. Copy the web.config file and paste it into your local folder. 

Stop the below services before changing the file.

  • IIS
  • World wide publishing
  • MS Dynamics 365 Batch
  • MS Dynamics 365 DIXF
  • Close the VS

8. Make the below changes to the file, then replace the original file in the AoSService\WebRoot folder. Remember to back up the original file before making any changes.   

  • DataAccess.Database
  • DataAccess.DBServer
  • DataAccess.SqlPwd
  • DataAccess.SqlUser
<add key="DataAccess.Database" value="<example_axdb_fromAzure>" />
<add key="DataAccess.DbServer" value="<example_axdb_server.database.windows.net>" />
<add key="DataAccess.SqlPwd" value="<axdbadmin_password_from_LCS>" />
<add key="DataAccess.SqlUser" value="axdbadmin" />
<add key="DataAccess.AxAdminSqlPwd" value="<axdbadmin_password_from_LCS>" />
<add key="DataAccess.AxAdminSqlUser" value="axdbadmin" />

8. Run Command Prompt (CMD) as an administrator and execute the command iisreset.

9. Connect to the SQL server using the provided details.

        1. server name

        2. User name

        3. Password

10. Click on Advanced and Give the data base name and click on connect.

Reference : Click here

Keep Daxing!!


Thursday, January 23, 2025

How to apply like operator, order by in D365 Odata URL.

  How to apply like operator, orderby in D365 Odata URL.

like operator in D365 Odata URL.


1. While fetching data from D365, we can apply filters.

2. In some cases, we may need to use a "like" operator.

3. To achieve this, we need to include a * in the text.

{{resource}}/data/VendorGroups?Cross-company=true&$filter=Description eq '*Test*'

4. I have tested this with three scenarios, as listed below:

  •     '*     ' -->   Prefix 
  •     '     *' -->   Suffix
  •     '*   *' --> Prefix and Suffix


With Select:

{{resource}}/data/VendorGroups?Cross-company=true&$select=VendorGroupId,DefaultPaymentTermName,Description
        &$filter=Description eq '*Test*'

Order by operator in D365 Odata URL.

1. We can apply order by for more than one field.
{{resource}}/data/VendorGroups?Cross-company=true&$orderby=dataAreaId,VendorGroupId


With Select:
{{resource}}/data/VendorGroups?Cross-company=true&$select=dataAreaId,VendorGroupId,DefaultPaymentTermName,Description
    &$orderby=dataAreaId,VendorGroupId

2. Applied order by for VendGroupId field.




MS ODATA URL

    Keep daxing!!

Monday, January 20, 2025

How to Generate a D365 Token in Logic App

There are two ways to trigger D365:

Way 1. Generate the Token 

    In this method, you generate the D365 token first and then use it to trigger D365.

    Steps to Generate the Token:

        1. Use the following URL:

        https://login.microsoftonline.com/@{parameters('Tenant Id')}/oauth2/v2.0/token

        2. Add the required Headers as below:

    {
          "Content-Type": "application/x-www-form-urlencoded"
    }

        3. Use the following format in the body:

        client_id=@{parameters('Client id')}
        &scope=@{parameters('D365URL')}%2F.default
        &client_secret=@{parameters('Client secret')}
        &grant_type=client_credentials

        Once the token is generated, you can use it to trigger D365.

        Expression:

     {
         "Authorization" : "Bearer @{body('Generate_D365_Token')?['access_token']}"
     }

            The token remains valid for up to 1 hour, allowing you to reuse it for multiple triggers during this time.

        Output:


Way2. Pass the Values Directly

        In this method, you do not need to generate a token separately. Instead, you pass the Client ID, Client Secret, and Tenant ID directly in the same step.


If you are triggering D365 multiple times within a Logic App, you must pass these values for each step.



Keep Daxing!!

Thursday, January 16, 2025

How to get total record count and Top 10 records from D365 Odata GET URL.

How to get total record count, Top 10 records from D365 Odata URL.

Get Total Record count by Odata URL.

1. To retrieve the total record count, we need to use the $count=true keyword in the URL.
{{resource}}/data/VendorGroups?Cross-company=true&$count=true


Get Top 3 records by Odata URL.

1. To retrieve the top 3 records, We need to use $top=3 keyword in the URL.
{{resource}}/data/VendorGroups?Cross-company=true&$top=3

Keep Daxing!!

Wednesday, January 8, 2025

How to Fetch Header and Line Information in a Single D365 OData GET URL

How to Fetch 2 entities Information in a Single D365 OData GET URL


1. When using the GET operation, it retrieves all information from the specified entity by default.

2. In some cases, we need information from two related tables, such as header and line data. For this we need to trigger D365 twice with different URL.

3. To achieve this, a relationship must exist between these two entities.

4. In the example below, I fetched data from PurchaseOrderHeadersV2 and PurchaseOrderLinesV2.
   
    The below purchase order has 2 lines:


5. I used the
$expand keyword to include data from the related table and $select to specify the fields to retrieve.

{{resource}}/data/PurchaseOrderHeadersV2?$filter=dataAreaId eq 'USMF' and PurchaseOrderNumber eq 'PO-000218'
  &Cross-company=true&$select=dataAreaId,PurchaseOrderNumber,OrderVendorAccountNumber,PurchaseOrderName,PurchaseOrderStatus
  &$expand=PurchaseOrderLinesV2 ($select=dataAreaId,PurchaseOrderNumber,LineNumber,OrderedPurchaseQuantity,ItemNumber,PurchasePrice)

6. Below is an example URL without using the $select keyword:

{{resource}}/data/PurchaseOrderHeadersV2?$filter=dataAreaId eq 'USMF' and PurchaseOrderNumber eq 'PO-000218'
  &Cross-company=true&$select=dataAreaId,PurchaseOrderNumber,OrderVendorAccountNumber,PurchaseOrderName,PurchaseOrderStatus
  &$expand=PurchaseOrderLinesV2



Without Purchase order filter.

{{resource}}/data/PurchaseOrderHeadersV2?$filter=dataAreaId eq 'USMF' &Cross-company=true
&$select=dataAreaId,PurchaseOrderNumber,OrderVendorAccountNumber,PurchaseOrderName,PurchaseOrderStatus
&$expand=PurchaseOrderLinesV2 ($select=dataAreaId,PurchaseOrderNumber,LineNumber,OrderedPurchaseQuantity,ItemNumber,PurchasePrice)


MS ODATA URL


Keep daxing!!


Monday, January 6, 2025

How to Select Required Fields in D365 OData URL

How to Select Required Columns in a D365 OData URL.



1. When using the GET operation, the system retrieves all the fields available in the data entity by default.

2. In real-time scenarios, we need only specific fields for our process. To achieve this, we can use the $select keyword in the GET URL.

3. Using $select, you can specify the fields that you want to retrieve.
?$select=FieldNames

4. Below is an example URL I used for testing:
{{resource}}/data/VendorGroups?Cross-company=true
    &$select=VendorGroupId,DefaultPaymentTermName,Description


5. Below is the output:





In the above URL, no filter was applied. If you want to retrieve a specific record, you can apply a filter by adding the $filter keyword to the URL.


I applied a filter using the dataAreaId and vendGroupId fields.
{{resource}}/data/VendorGroups?Cross-company=true&$filter=dataAreaId eq 'USMF' 
and VendorGroupId eq '10'
&$select=dataAreaId,VendorGroupId,DefaultPaymentTermName,Description


Keep Daxing!!

Wednesday, January 1, 2025

How to assign the generated token to a global variable and use it in Postman

How to assign the generated token to a global variable and use of environments in Postman:

            Copying the token and assigning it to different requests can be difficult. Instead, you can create a variable and assign the token to that variable. In your requests, you can use the variable directly. Simply trigger the token URL, and then proceed to trigger your GET or POST requests.

Generate Token and Assign to Global variable: 

           1. Click on the main collection, which will populate the right-side window. Select the "Variables" tab and add the variables you need.

                For the Resource variable, I am assigning my dev machine URL.

            2. For the AccessToken variable field, I want to capture the generated token after triggering the API.

            3.Create an environment using the option at the top right side.

            4.After creating the environment, select the highlighted option and click on "Edit." Add the variable and save it.

            5. To capture the token, write the following JavaScript code under the "Scripts" tab of the API request that generates the token:

    var access_token = pm.response.json().access_token;
    pm.environment.set("accessToken", access_token)

            6. After clicking the "Send" button, the system will assign the generated token to my "AccessToken" variable.


Different Environments:

            Instead of creating different variables, we can create different environments and maintain different values for the same variable based on the environment.

1.On the top-right corner, you will find the Environment window. Click on the + symbol to create a new environment.

2. Alternatively, you can click on the Environments option on the left side. Here, you will see the environments available in Postman.

3. You can create variables as required for your process.

4. Maintain the same variable name across all environments.

5. Use this variable in your request and click Send. For testing purposes, I have provided a dummy name.

Keep Daxing!!