Dynamics crm 如何在Dynamics 365中使用C#Web API
我正在使用Dynamics 365的在线实例。我已经创建了C#Web API来从活动实体导出数据。当我从VisualStudio运行它时,它工作得很好 现在我想在Dynamics 365中单击按钮调用它。要求是,当用户单击按钮时,应调用Web API并导出数据。 我不知道如何完成这项任务。谁能帮我解决这个问题。请为我提供获得此任务的步骤。 下面给出了Web API代码Dynamics crm 如何在Dynamics 365中使用C#Web API,dynamics-crm,dynamics-crm-365,dynamics-365-sales,Dynamics Crm,Dynamics Crm 365,Dynamics 365 Sales,我正在使用Dynamics 365的在线实例。我已经创建了C#Web API来从活动实体导出数据。当我从VisualStudio运行它时,它工作得很好 现在我想在Dynamics 365中单击按钮调用它。要求是,当用户单击按钮时,应调用Web API并导出数据。 我不知道如何完成这项任务。谁能帮我解决这个问题。请为我提供获得此任务的步骤。 下面给出了Web API代码 using System; using System.Collections.Generic; using System.Con
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.ServiceModel;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;
using Microsoft.Xrm.Sdk;
using System.Windows.Forms;
namespace Experiments
{
class Program
{
private static OrganizationService _orgService;
static void Main(string[] args)
{
try
{
CrmConnection connection = CrmConnection.Parse(ConfigurationManager.ConnectionStrings["CrmOnline"].ConnectionString);
using (_orgService = new OrganizationService(connection))
{
var exportToExcelRequest = new OrganizationRequest("ExportToExcel");
exportToExcelRequest.Parameters = new ParameterCollection();
//Has to be a savedquery aka "System View" or userquery aka "Saved View"
//The view has to exist, otherwise will error out
exportToExcelRequest.Parameters.Add(new KeyValuePair<string, object>("View", new EntityReference("savedquery", new Guid("{00000000-0000-0000-00AA-000010001902}"))));
exportToExcelRequest.Parameters.Add(new KeyValuePair<string, object>("FetchXml", @"<?xml version='1.0'?>
<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>
<entity name='activitypointer'>
<attribute name='subject'/>
<attribute name='ownerid'/>
<attribute name='prioritycode'/>
<attribute name='regardingobjectid'/>
<attribute name='activitytypecode'/>
<attribute name='statecode'/>
<attribute name='scheduledstart'/>
<attribute name='scheduledend'/>
<attribute name='activityid'/>
<attribute name='instancetypecode'/>
<attribute name='community'/>
<attribute name='senton'/>
<attribute name='statuscode'/>
<order descending='false' attribute='scheduledend'/>
<filter type='and'>
<condition attribute='actualdurationminutes' value='43800' operator='le'/>
</filter>
<link-entity name='systemuser' alias='activitypointerowningusersystemusersystemuserid' link-type='outer' visible='false' to='owninguser' from='systemuserid'>
<attribute name='internalemailaddress'/>
</link-entity>
<link-entity name='email' alias='email_engagement' link-type='outer' visible='false' to='activityid' from='activityid'><attribute name='isemailfollowed'/>
<attribute name='lastopenedtime'/>
<attribute name='delayedemailsendtime'/>
</link-entity>
</entity>
</fetch>"));
exportToExcelRequest.Parameters.Add(new KeyValuePair<string, object>("LayoutXml", @"
<grid name='resultset' object='2' jump='fullname' select='1' icon='1' preview='1'>
<row name='result' id='activitypointerid'>
<cell name='activitytypecode' width='150' />
<cell name='statecode' width='112' />
<cell name='scheduledstart' width='110' />
<cell name='scheduledend' width='110' />
</row>
</grid>"));
//need these params to keep org service happy
exportToExcelRequest.Parameters.Add(new KeyValuePair<string, object>("QueryApi", ""));
exportToExcelRequest.Parameters.Add(new KeyValuePair<string, object>("QueryParameters",new InputArgumentCollection()));
var exportToExcelResponse = _orgService.Execute(exportToExcelRequest);
if (exportToExcelResponse.Results.Any())
{
File.WriteAllBytes("Activities.xlsx", exportToExcelResponse.Results["ExcelFile"] as byte[]);
}
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
string message = ex.Message;
throw;
}
}
}
}
Thanks.
使用系统;
使用System.Collections.Generic;
使用系统配置;
使用System.IO;
使用System.Linq;
使用System.ServiceModel;
使用Microsoft.Crm.Sdk.Messages;
使用Microsoft.Xrm.Client;
使用Microsoft.Xrm.Client.Services;
使用Microsoft.Xrm.Sdk;
使用System.Windows.Forms;
名称空间实验
{
班级计划
{
私有静态组织服务_orgService;
静态void Main(字符串[]参数)
{
尝试
{
CrmConnection connection=CrmConnection.Parse(ConfigurationManager.ConnectionString[“CrmOnline”].ConnectionString);
使用(_orgService=新组织服务(连接))
{
var exportToExcelRequest=新组织请求(“ExportToExcel”);
exportToExcelRequest.Parameters=新参数collection();
//必须是savedquery又名“系统视图”或userquery又名“已保存视图”
//视图必须存在,否则将出错
exportToExcelRequest.Parameters.Add(新的KeyValuePair(“视图”,新的EntityReference(“savedquery”,新的Guid({00000000-0000-0000-00AA-000011902})));
exportToExcelRequest.Parameters.Add(新的KeyValuePair(“FetchXml”),@)
"));
exportToExcelRequest.Parameters.Add(新的KeyValuePair(“LayoutXml”),@)
"));
//需要这些参数来使组织服务满意
exportToExcelRequest.Parameters.Add(新的KeyValuePair(“QueryApi”),“”);
exportToExcelRequest.Parameters.Add(新的KeyValuePair(“QueryParameters”,新的InputArgumentCollection());
var exportToExcelResponse=\u orgService.Execute(exportToExcelRequest);
if(exportToExcelResponse.Results.Any())
{
File.writealBytes(“Activities.xlsx”,exportToExcelResponse.Results[“ExcelFile”]作为字节[]);
}
}
}
捕获(FaultException-ex)
{
字符串消息=例如消息;
投
}
}
}
}
谢谢
我建议您将您的C#代码编译为,并将其作为工作流程中的一个步骤。有关如何从工作流调用自定义操作的信息,请参见
然后我建议您安装。这将允许您自定义表单和导航,以添加一个或多个按钮。您可以使用工作台自定义这些按钮,设置它们的命令以调用工作流,而工作流反过来调用您的操作(您的C代码)
请注意,要实现您的要求,有几种解决方案,我刚刚建议了一种。其他解决方案可能包括JavaScript和调用Web API客户端。由于您使用的是Dynamics 365 online,我建议您使用CDS连接器创建Microsoft FLOW应用程序。希望这有帮助 我一直在寻找确切的解决方案,以调用工作流来调用操作。你能解释一下我们如何配置这个按钮吗?在添加命令操作时,我只能看到
Url操作
和Javascript操作
我假设您已经尝试了现成的数据导出功能?