无法使用外部包装程序(davidyack)在mvc内核中执行MSCRM Webapi自定义绑定操作

时间:2019-06-28 23:02:58

标签: c# dynamics-crm action

我无法使用David Yack包装的mscrm webapi github在MSCRM中执行绑定的自定义操作。我可以使用MSCRM SDK库轻松执行Action,但是当我使用MVC core 2.2时,这些DLL对我不可用,并且我发现的最佳替代方法是david的包装器,尽管在文档方面较薄,但效果很好。

我尝试了各种执行动作的方法。如果该动作是没有参数的未绑定自定义动作,我就能开始工作。我对实体绑定操作和传递参数以及关联的实体ID没有好运。

我尝试在文档中找到一个c#示例,但是事实证明这很困难。

我试图在下面的SDK代码中实现相同的功能,但是使用David的包装程序。

OrganizationRequest request = new OrganizationRequest("new_GetProductBuyPrice");
request["Target"] = new EntityReference("product", new Guid(ProductID));
request["Account"] = new EntityReference("account", new Guid(AccountID));
request["Currency"] = new EntityReference("transactionalcurrency", new Guid(CurrencyID));
request["Qty"] = 1.00m;

OrganizationResponse response = Xrm.XrmSvc.Execute(request);
UnitBuy = Math.Round(((Money)response.Results["BuyPrice"]).Value, 2);
DiscountReason = response.Results.Contains("DiscountReason") ? response.Results["DiscountReason"].ToString() : string.Empty;

如何在我的CRM中用我的自定义操作执行大卫的包装?

1 个答案:

答案 0 :(得分:0)

因此,我们设法使用github上的David Yack API包装器解决了这个问题,并只是发布了我的发现,以防万一有人偶然发现这篇文章。它们的关键是像使用Microsoft SDK中的EntityReference类一样使用Dictionary,并使用“ @ odata.type”作为entitytype和entityid均小写,如下所示:

dynamic AccountRef = new Dictionary<String, object>();
            AccountRef["@odata.type"] = "Microsoft.Dynamics.CRM.account";
            AccountRef["accountid"] = AccountId.ToString();

            dynamic CurrencyRef = new Dictionary<String, object>();
            CurrencyRef["@odata.type"] = "Microsoft.Dynamics.CRM.transactioncurrency";
            CurrencyRef["transactioncurrencyid"] = CurrencyId.ToString();

            var actionParams = new
            {
                Account = AccountRef,
                Currency = CurrencyRef,
                Qty = 1.00m
            };
            var response = await _crmClient.API.ExecuteAction("Microsoft.Dynamics.CRM.new_GetProductBuyPrice", "products", ProductId, actionParams);
相关问题