Dynamics 365 Business Central: How to set dimension via standard API and Can we do it via Power Automate?

Dynamics 365 Business Central

Hi, Readers.
Today I would like to briefly talk about how to set dimension via standard API and can we do it in Power Automate?
Dimensions are values that categorize entries so you can track and analyze them on documents, such as sales orders. Dimensions can, for example, indicate the area or department an entry came from.

Is it possible to manage this value using the API? Yes, Microsoft has prepared a standard API.

dimensionSetLine resource type: Represents a dimension set line in Business Central.

Methods

MethodReturn TypeDescription
GET dimensionSetLinedimensionSetLineGets a dimension set line object.
DELETE dimensionSetLinenoneDeletes a dimension set line object.
POST dimensionSetLinedimensionSetLineCreates a dimension set line object.
PATCH dimensionSetLinedimensionSetLineUpdates a dimension set line object.

Navigation

NavigationReturn TypeDescription
salesInvoicesalesInvoiceGets the salesinvoice of the dimensionSetLine.
salesInvoiceLinesalesInvoiceLineGets the salesinvoiceline of the dimensionSetLine.
dimensiondimensionGets the dimension of the dimensionSetLine.
customerPaymentcustomerPaymentGets the customerpayment of the dimensionSetLine.
journalLinejournalLineGets the journalline of the dimensionSetLine.
timeRegistrationEntrytimeRegistrationEntryGets the timeregistrationentry of the dimensionSetLine.
generalLedgerEntrygeneralLedgerEntryGets the generalledgerentry of the dimensionSetLine.
salesOrdersalesOrderGets the salesorder of the dimensionSetLine.
salesOrderLinesalesOrderLineGets the salesorderline of the dimensionSetLine.
salesQuotesalesQuoteGets the salesquote of the dimensionSetLine.
salesQuoteLinesalesQuoteLineGets the salesquoteline of the dimensionSetLine.
salesCreditMemosalesCreditMemoGets the salescreditmemo of the dimensionSetLine.
salesCreditMemoLinesalesCreditMemoLineGets the salescreditmemoline of the dimensionSetLine.
purchaseInvoicepurchaseInvoiceGets the purchaseinvoice of the dimensionSetLine.
purchaseInvoiceLinepurchaseInvoiceLineGets the purchaseinvoiceline of the dimensionSetLine.
vendorPaymentvendorPaymentGets the vendorpayment of the dimensionSetLine.
salesShipmentsalesShipmentGets the salesshipment of the dimensionSetLine.
salesShipmentLinesalesShipmentLineGets the salesshipmentline of the dimensionSetLine.
purchaseReceiptpurchaseReceiptGets the purchasereceipt of the dimensionSetLine.
purchaseReceiptLinepurchaseReceiptLineGets the purchasereceiptline of the dimensionSetLine.
purchaseOrderpurchaseOrderGets the purchaseorder of the dimensionSetLine.
purchaseOrderLinepurchaseOrderLineGets the purchaseorderline of the dimensionSetLine.

PS: Dynamics 365 Business Central: How to use filter expressions in API related resource ($expand)

Properties:

PropertyTypeDescription
idGUIDThe unique ID of the dimension set line. Non-editable.
codestringThe code of the dimension set line.
parentIdGUIDThe ID of the parent entity.
parentTypeNAV.dimensionSetEntryBufferParentTypeThe type of the parent document of the dimension set line. It can be ” “, “Journal Line”, “Sales Order”, “Sales Order Line”, “Sales Quote”, “Sales Quote Line”, “Sales Credit Memo”, “Sales Credit Memo Line”, “Sales Invoice”, “Sales Invoice Line”, “Purchase Invoice”, “Purchase Invoice Line”, “General Ledger Entry” or “Time Registration Entry”.
displayNamestringSpecifies the dimension set line’s name. This name will appear on all sales documents for the dimension set line.
valueIdGUIDThe unique ID of the value of the dimension.
valueCodestringThe code of the value of the dimension.
valueDisplayNamestringThe display name of the value of the dimension. Read-Only.

Source code: page 30022 “APIV2 – Dimension Set Lines”

Let’s look at some simple examples.

Get:

salesOrders -> dimensionSetLines

https://api.businesscentral.dynamics.com/v2.0/c8558e71-6ad8-4fcd-9f29-3ca165b41bbe/Sandbox223/api/v2.0/companies(554f4f15-9c8e-ee11-be3e-6045bde96b9a)/salesOrders(28ac0679-16b4-ee11-a56a-000d3accbc4a)/dimensionSetLines

Response:

        {
            "@odata.etag": "W/\"JzE5OzMyMDgxNjE2NDkzMjc2NTM1MDcxOzAwOyc=\"",
            "id": "14be2193-90ab-ee11-a56a-6045bd686202",
            "code": "AREA",
            "consolidationCode": "",
            "parentId": "28ac0679-16b4-ee11-a56a-000d3accbc4a",
            "parentType": "Sales_x0020_Order",
            "displayName": "Area",
            "valueId": "77fb0da5-90ab-ee11-a56a-6045bd686202",
            "valueCode": "40",
            "valueConsolidationCode": "",
            "valueDisplayName": "Europe North (Non EU)"
        }

PS: In BC

Another example:
purchaseInvoices -> dimensionSetLines

https://api.businesscentral.dynamics.com/v2.0/c8558e71-6ad8-4fcd-9f29-3ca165b41bbe/Sandbox223/api/v2.0/companies(554f4f15-9c8e-ee11-be3e-6045bde96b9a)/purchaseInvoices(3ca0d8f6-fdb3-ee11-a56a-000d3accbc4a)/dimensionSetLines

Post:

https://api.businesscentral.dynamics.com/v2.0/c8558e71-6ad8-4fcd-9f29-3ca165b41bbe/Sandbox223/api/v2.0/companies(554f4f15-9c8e-ee11-be3e-6045bde96b9a)/salesOrders(28ac0679-16b4-ee11-a56a-000d3accbc4a)/dimensionSetLines

Header:

Body:

{
    "parentId": "28ac0679-16b4-ee11-a56a-000d3accbc4a",
    "code": "BUSINESSGROUP",
    "valueCode": "Home"
}

Patch:

https://api.businesscentral.dynamics.com/v2.0/c8558e71-6ad8-4fcd-9f29-3ca165b41bbe/Sandbox223/api/v2.0/companies(554f4f15-9c8e-ee11-be3e-6045bde96b9a)/salesOrders(28ac0679-16b4-ee11-a56a-000d3accbc4a)/dimensionSetLines(15be2193-90ab-ee11-a56a-6045bd686202)

Header:

Body:

This is not difficult. So the next question is, is this possible via Power Automate? Unfortunately, as of now, this cannot be done via the standard API. Although this standard API can be selected in the Power Automate trigger.

But it will prompt the following error. (Parent Id is already set)

ErrorCode: Application_DialogException
You must get to the parent first to create a dimension set line.

Why? AJ gave a detailed explanation. More details: Link

There is a difference between Power Automate and Postman. In Power Automate, the URL becomes this:

POST /api/v2.0/dimensionSetLines

while in Postman the URL is this:

POST /api/v2.0/salesOrders(id)/dimensionSetLines

With the URL in Postman, there is a filter applied to dimensionSetLines from the salesOrders API page. That’s because dimensonSetLines is a subpage of salesOrder. The Business Central connector in Power Automate doesn’t support this. Instead, it calls directly dimensionSetLines, without any filter. A filter can’t be specified, if you try that, then the BC connector will simply fail.

It’s impossible to achieve this from Power Automate with the standard BC connector. Even a deep insert (lines + dimensions) is failing. The only option would be to create a custom API or use the standard HTTP connector.

PS:
1. Using OAuth 2.0 to connect Business Central APIs and Web Services in Power Automate – OAuth in HTTP action (standard HTTP action in Power Automate)

2. For the default dimensions of master data, please use the standard API below.
defaultDimension resource type: Represents a default dimensions in Business Central.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL