MSCRM 4 使用InitializeFromRequest 将标准实体转换为自定义实体

发布于 2024-09-04 18:13:30 字数 1223 浏览 5 评论 0原文

我正在尝试使用 InitializeFromRequest 使用以下代码将订单和 orderdetail 行转换为自定义实体及其子行:

public void Convert(Guid FromEntityId, string FromEntityName, string ToEntityName)
{
    try
    {
        // Set up the CRM Service.
        CrmService _service = GetCrmService();

        InitializeFromRequest req = new InitializeFromRequest();
        req.EntityMoniker = new Moniker(); // this is the very thing that does the job.

        req.EntityMoniker.Id = FromEntityId;
        req.EntityMoniker.Name = FromEntityName;
        req.TargetEntityName = ToEntityName;  //contact for our example req.

        req.TargetFieldType = TargetFieldType.ValidForCreate;
        InitializeFromResponse rps = (InitializeFromResponse)_service.Execute(req);
        //now the lead is converted to a contact, and you can see it in contacts.
        Guid entityId = _service.Create(rps.Entity);
        lblMsg.Text = "Done ID:" + entityId.ToString();
    }            
    catch (System.Web.Services.Protocols.SoapException se)
    {
        lblMsg.Text = "soap:" + se.Detail.InnerText;
    }
    catch (Exception ex)
    {
        lblMsg.Text = ex.Message;
    }
}

现在我能够创建一个自定义实体,但所有属性都是空的,尽管我在关系。

我错过了什么或做错了什么?

I'm trying to convert an order and orderdetail lines to a custom entity and its child lines using InitializeFromRequest using the code below:

public void Convert(Guid FromEntityId, string FromEntityName, string ToEntityName)
{
    try
    {
        // Set up the CRM Service.
        CrmService _service = GetCrmService();

        InitializeFromRequest req = new InitializeFromRequest();
        req.EntityMoniker = new Moniker(); // this is the very thing that does the job.

        req.EntityMoniker.Id = FromEntityId;
        req.EntityMoniker.Name = FromEntityName;
        req.TargetEntityName = ToEntityName;  //contact for our example req.

        req.TargetFieldType = TargetFieldType.ValidForCreate;
        InitializeFromResponse rps = (InitializeFromResponse)_service.Execute(req);
        //now the lead is converted to a contact, and you can see it in contacts.
        Guid entityId = _service.Create(rps.Entity);
        lblMsg.Text = "Done ID:" + entityId.ToString();
    }            
    catch (System.Web.Services.Protocols.SoapException se)
    {
        lblMsg.Text = "soap:" + se.Detail.InnerText;
    }
    catch (Exception ex)
    {
        lblMsg.Text = ex.Message;
    }
}

Now I am able to get a custom entity created but all the attributes are empty despite me setting the mapping fields in the realtionship.

What am I missing or doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫负雪 2024-09-11 18:13:30

将标准实体转换为自定义实体时,您需要设置 ReturnDynamicEntities = true。

You need to set ReturnDynamicEntities = true when converting an standard entity to a custom one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文