CosmosDB patch operation changes datatype from numeric to string

Martin Peters 6 Reputation points
2024-08-15T06:50:29.4733333+00:00

I'm performing a patch operation on a numeric field in CosmosDB using the CosmosDB connector in Logic Apps Standard.

The patch operation changes the field from numeric to string which is not what I want.

Inputs:

{
  "containerId": "SalesInvoices",
  "databaseId": "ODS",
  "itemId": "FAC000000427",
  "partitionKey": "FAC000000427",
  "patchOperations": [
    {
      "path": "/InvoiceTotals/InvoiceAmount",
      "type": "Replace",
      "value": 30.06
    },
    {
      "path": "/InvoiceTotals/PaidAmount",
      "type": "Replace",
      "value": 0
    },
    {
      "path": "/InvoiceTotals/OutstandingAmount",
      "type": "Replace",
      "value": 30.06
    }
  ]
}

Outputs:
{
  "Id": "FAC000000427",
  "ActivityId": "0ecba59b-ba6b-432c-8a8b-8cd9f69ece89",
  "RequestCharge": 14.22,
  "Content": {
    "InvoiceId": "FAC000000427",
    "InvoiceDate": "2024-07-10",
    "InvoiceTime": "12:00:00",
    "DueDate": "2024-08-09T12:00:00Z",
    "Currency": "EUR",
    "PaymentMethod": "Invoice",
    "PaymentCondition": "30DGN",
    "Relation": [
      {
        "Type": "Customer",
        "Id": "9999936"
      }
    ],
    "Status": "open",
    "InvoiceTotals": {
      "LineDiscountAmount": 10.08,
      "SubTotalAmount": 13.92,
      "InvoiceDiscountAmount": 0,
      "SurchargeAmount": 0,
      "VATAmount": 2.92,
      "InvoiceAmount": "30.06",
      "PaidAmount": 0,
      "OutstandingAmount": "30.06"
    },
...
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,203 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,665 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 26,261 Reputation points
    2024-08-27T21:15:56.2266667+00:00

    Instead of passing the number directly in the value field, you can use the following format:

    {
      "path": "/InvoiceTotals/InvoiceAmount",
      "type": "Replace",
      "value": "@float(30.06)"
    }
    

    As a workaround, after the patch operation, you can perform a validation step to check the types and convert them back if necessary. However, this would add additional complexity and might not be ideal.

    Sometimes, the SDK or connector might have issues with data types. If you're using an older version of the CosmosDB SDK or the Logic App connector, consider updating to the latest version to see if this resolves the issue. Microsoft occasionally patches these types of issues in newer versions.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.