我正在尝试以编程方式将资源分配给Dynamics 365中的任务。代码是:
private static void AssignResourceToTask(XrmServiceContext xrm)
{
Guid TaskId = new Guid("e0bdf7c7-6a14-e711-8114-e0071b6ac161");
Guid ResourceId = new Guid("cd01ae07-b9cd-e611-80e7-c4346bac0910");
Guid ProjectId = new Guid("7982feea-a0f2-e611-8130-e0071b6a92f1");
var AssignResource = new msdyn_resourceassignment
{
msdyn_resourceassignmentId = Guid.NewGuid(),
msdyn_bookableresourceid = new Microsoft.Xrm.Client.CrmEntityReference("bookableresource", ResourceId),
msdyn_taskid = new Microsoft.Xrm.Client.CrmEntityReference("msdyn_projecttask", TaskId),
msdyn_projectid = new Microsoft.Xrm.Client.CrmEntityReference("msdyn_project", ProjectId),
};
AssignResource.msdyn_bookableresourceid.Name = "Amy Alberts";
xrm.AddObject(AssignResource);
xrm.SaveChanges();
}
但我无法使用上述代码为任务分配资源。
答案 0 :(得分:0)
你试过Microsoft.Crm.Sdk.AssignRequest吗?您的代码如下:
_serviceProxy.EnableProxyTypes();
_service = (IOrganizationService)_serviceProxy;
var assignRequest = new AssignRequest
{
Assignee = new EntityReference("contact", ResourceId),
Target = new EntityReference("task", TaskId)
};
_service.Execute(assignRequest);
Microsoft有一个示例here。