最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

使用 OData 批处理在 D365FO 中创建多条记录Creating multiple records in D365FO using OData batch

网络文摘 William 2浏览 0评论

大家好,

在今天的文章中,我将尝试解释如何在 Dynamics 365 财务与运营(D365FO)使用单一 OData 批处理 请求。示例中使用了Postman,展示了批次中每个部分如何 有效载荷工作,包括边界、头部和常见陷阱。

[请先阅读并理解完整内容后再使用示例。]

  1. 概述

OData批处理允许你一次性发送多个操作 HTTP 请求。这在你想同时创建多个记录时非常有用, 例如多个账簿日记头。而不是单独发送POST邮件 请求时,你会把它们包裹在一批次和变革集里。

  • 批次会把所有东西分组在一起。
  • 变更集组编写操作(POST、PATCH、DELETE)并执行 交易型。
  • 每人 记录创建是变更集内的一个应用程序/HTTP 部分。
  1. 完整批处理有效载荷示例
  1. 理解有效载荷的每个部分

批次边界: 该批次开头有:

–batch_7bf57939-a923-4e49-92d3-20fb4f2c8435

该边界必须与主边界中申报的边界一致 HTTP 头部:

内容类型:多部分/混合; 边界=batch_7bf57939-A923-4E49-92D3-20FB4F2C8435

该批次结束时:

——batch_7bf57939-a923-4e49-92d3-20fb4f2c8435——

变更集边界

在批次中,你声明一个变更集:

内容类型:多部分/混合; 边界=changeset_8a6f6ebe-e9C9-44A2-B980-C33A69370EB4

每个POST请求都被包裹在这个变更集内。该 变革集结尾:

–changeset_8a6f6ebe-e9c9-44a2-b980-c33a69370eb4–

个别行动

每个操作开始时:

——changeset_……

内容类型:application/http

内容传输编码:二进制

Content-ID:<唯一编号>

Content-ID 用于识别操作。它变成了 在操作间引用结果时非常重要。

内部 HTTP 请求

每个操作都包含一个完整的 HTTP 请求:

POST /data/LedgerJournalHeaders HTTP/1.1

Content-Type: application/json;odata.metadata=minimal

接受:application/json;odata.metadata=minimal

公司:美国海军

偏好:返回=表示

关键头部:

  • 公司: 指定法律实体。
  • 偏好: return=representation:返回响应中创建的记录。

JSON正文紧随空白行之后。

  1. 如何用邮递员发送
  1. 赛场 POST方法。
  2. 网址:
  3. https://<你的环境>.cloudax.dynamics.com/data/$batch
  4. 添加 标题:
    • 授权: 持有人<令牌>
    • 内容类型: 多部分/混合;边界=batch_7bf57939-A923-4E49-92D3-20FB4F2C8435
    • 接受: application/json
  5. 粘土 整个批次有效载荷进入正文(原始文本)。

重要提示:

  • 做 不要在边界线前加额外的空格。
  • 确保 需要时会保留空白行。
  • 边界 名字必须完全一致。
  1. 常见陷阱
  • 边界 不匹配:最常见的错误原因。
  • 失踪 空白行:标题与正文之间必须。
  • 错误 公司头:可能导致数据在错误的法律页面创建 实体。
  • 变换组 错误:如果一个操作失败,变更集中的所有操作都会失败。
  1. 摘要

在D365FO中使用OData批处理可以创建多个 记录高效地集中在一次请求中。理解边界、头部和 格式对于成功执行至关重要。所提供的例子可以是 用作创建多个Ledger Journal头或其他任何模板 实体记录。

希望你觉得这篇帖子有用,如果需要更多例子,欢迎留言。

——哈利 关注我们的Facebook,保持我们的动态。https:fb.com/theaxapta

Hi Folks,
In todays post I will try to explains how to create multiple records in
Dynamics 365 Finance & Operations (D365FO) using a single OData batch
request. The example uses Postman and demonstrates how each part of the batch
payload works, including boundaries, headers, and common pitfalls.
[Please read and understand the full content first before using the examples.]

1. Overview

OData batch allows you to send several operations in one
HTTP request. This is useful when you want to create multiple records at once,
such as multiple Ledger Journal Headers. Instead of sending separate POST
requests, you wrap them inside a batch and a changeset.

  • The batch
    groups everything together.
  • The changeset
    groups write operations (POST, PATCH, DELETE) and makes them
    transactional.
  • Each
    record creation is an application/http part inside the changeset.

2. Full Batch Payload Example

3. Understanding Each Part of the Payload

Batch Boundary : The batch begins with:

    –batch_7bf57939-a923-4e49-92d3-20fb4f2c8435

This boundary must match the boundary declared in the main
HTTP header:

    Content-Type: multipart/mixed;
boundary=batch_7bf57939-a923-4e49-92d3-20fb4f2c8435

The batch ends with:

    –batch_7bf57939-a923-4e49-92d3-20fb4f2c8435–

 

Changeset Boundary

Inside the batch, you declare a changeset:

    Content-Type: multipart/mixed;
boundary=changeset_8a6f6ebe-e9c9-44a2-b980-c33a69370eb4

Each POST request is wrapped inside this changeset. The
changeset ends with:

    –changeset_8a6f6ebe-e9c9-44a2-b980-c33a69370eb4–

 

Individual Operations

Each operation starts with:

–changeset_…

Content-Type: application/http

Content-Transfer-Encoding: binary

Content-ID: <unique number>

Content-ID is used to identify the operation. It becomes
important when referencing results between operations.

Inner HTTP Request

Each operation contains a full HTTP request:

POST /data/LedgerJournalHeaders HTTP/1.1

Content-Type: application/json;odata.metadata=minimal

Accept: application/json;odata.metadata=minimal

Company: usmf

Prefer: return=representation

Key headers:

  • Company:
    Specifies the legal entity.
  • Prefer:
    return=representation
    : Returns the created record in the response.

The JSON body follows after a blank line.

4. How to Send This in Postman

  1. Set
    method to POST.
  2. URL:
  3. https://<your-environment>.cloudax.dynamics.com/data/$batch
  4. Add
    headers:

    • Authorization:
      Bearer <token>
    • Content-Type:
      multipart/mixed; boundary=batch_7bf57939-a923-4e49-92d3-20fb4f2c8435
    • Accept:
      application/json
  5. Paste
    the entire batch payload into the body (raw text).

Important:

  • Do
    not add extra spaces before boundary lines.
  • Ensure
    blank lines exist where required.
  • Boundary
    names must match exactly.

5. Common Pitfalls

  • Boundary
    mismatch
    : The most common cause of errors.
  • Missing
    blank lines
    : Required between headers and body.
  • Incorrect
    Company header
    : May cause data to be created in the wrong legal
    entity.
  • Changeset
    errors
    : If one operation fails, all operations in the changeset fail.

6. Summary

Using OData batch in D365FO allows you to create multiple
records efficiently in a single request. Understanding boundaries, headers, and
formatting is essential for successful execution. The example provided can be
used as a template for creating multiple Ledger Journal Headers or any other
entity records.

Hope you find this post useful, pl drop a comment if you need some more examples.

-Harry
Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta

转载请注明:ww12345678 的部落格 | AX Helper » 使用 OData 批处理在 D365FO 中创建多条记录Creating multiple records in D365FO using OData batch

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny