使用c#(插件或其他方式)完成在线CRM 2015
本文关键字:在线 CRM 2015 方式 插件 其他 使用 | 更新日期: 2023-09-27 18:18:01
我希望做以下事情(我使用。net 4.5,在线crm-2015)
- 特定设备和设施资源可能无法在某一天进行调度
- 这是通过代码通过c#在一个插件或一个简单的web应用程序
- 用户将选择设备/设施,休息日。
- 在资源不可用于任何服务活动的选定日期(通过CRM UI中的服务日历)
我已经为休假写了这段代码。代码是从网上拷贝的
// svc is the IOrgService already instantiated
//Guid facilityID =this is the id for the facility
//Get the calendar id of the facility
Entity facilityEntity = svc.Retrieve(CrmEarlyBound.Equipment.EntityLogicalName, facilityID, new ColumnSet(new String[] { "calendarid" }));
// Retrieve the calendar of the facility(whole entity)
Entity facilityCalendarEntity = svc.Retrieve("calendar", ((Microsoft.Xrm.Sdk.EntityReference)(facilityEntity.Attributes["calendarid"])).Id
, new ColumnSet(true));
// Retrieve the calendar rules defined in the calendar
EntityCollection calendarRules = (EntityCollection)facilityCalendarEntity.Attributes["calendarrules"];
//Create a new inner calendar
CrmEarlyBound.Calendar newInnerCalendar = new CrmEarlyBound.Calendar();
newInnerCalendar.Type = new OptionSetValue(-1);
newInnerCalendar.Attributes["businessunitid"] = new EntityReference("businessunit", ((Microsoft.Xrm.Sdk.EntityReference)(userCalendarEntity["businessunitid"])).Id);
newInnerCalendar.Description = "my description";
newInnerCalendar.Name = "cal1";
Guid innerCalendarId = svc.Create(newInnerCalendar);
CrmEarlyBound.Calendar newInnerCalendar = new CrmEarlyBound.Calendar();
newInnerCalendar.Attributes["businessunitid"] = new EntityReference("businessunit", ((Microsoft.Xrm.Sdk.EntityReference)(facilityCalendarEntity["businessunitid"])).Id);
newInnerCalendar.Description = "my description";
newInnerCalendar.Name = "cal1";
Guid innerCalendarId = svc.Create(newInnerCalendar);
// Create a new calendar rule and assign the inner calendar id to it
Entity calendarRule = new Entity("calendarrule");
calendarRule.Attributes["description"] = "Time Off Rule";
calendarRule.Attributes["duration"] = 1440;
calendarRule.Attributes["extentcode"] = 2;
calendarRule.Attributes["pattern"] = "FREQ=DAILY;INTERVAL=1;COUNT=1";
calendarRule.Attributes["rank"] = 0;
calendarRule.Attributes["timezonecode"] = 85;
calendarRule.Attributes["innercalendarid"] = new EntityReference("calendar", innerCalendarId);
// starting at 12:00 on 7 May
calendarRule.Attributes["starttime"] = new DateTime(2016, 5, 10, 0, 0, 0, DateTimeKind.Utc);
calendarRules.Entities.Add(calendarRule);
//assign all the calendar rule back to the user calendar
facilityCalendarEntity.Attributes["calendarrules"] = calendarRules;
//update the user calendar entity that has the new rule
svc.Update(facilityCalendarEntity);
现在的问题:
工厂日历(工作时间)上没有显示任何内容。
如果您通过CRM UI做同样的事情,则在休息日显示红色标记,在我的情况下没有指示。
- 我无法更改同一设施创建此记录后的工作时间。
- 设置->服务管理->假期计划。我可以看到没有任何名称的新记录,但是当我试图打开相同的记录时,它给出了一个CRM错误。您也不能删除此记录
- 一旦我删除日历规则(通过代码),然后我可以回到Service Mgmt->Holiday Schedule并删除记录,一旦完成,我可以更改设施的工作时间。
你能告诉我我做错了什么吗?你将如何写代码来安排设施和设备的休息时间。
有几个问题。
首先,必须删除下面的代码段。这与用于创建不必要记录的变量相同。
CrmEarlyBound.Calendar newInnerCalendar = new CrmEarlyBound.Calendar();
newInnerCalendar.Type = new OptionSetValue(-1);
newInnerCalendar.Attributes["businessunitid"] = new EntityReference("businessunit", ((Microsoft.Xrm.Sdk.EntityReference)(userCalendarEntity["businessunitid"])).Id);
newInnerCalendar.Description = "my description";
newInnerCalendar.Name = "cal1";
Guid innerCalendarId = svc.Create(newInnerCalendar);
第二,你必须创建根/叶日历规则。
Entity calendarRule1 = new Entity("calendarrule");
// duration of 8 hours
calendarRule1.Attributes["duration"] = 480;
calendarRule1.Attributes["effort"] = 2.0;
calendarRule1.Attributes["issimple"] = true;
calendarRule1.Attributes["offset"] = 0;
calendarRule1.Attributes["rank"] = 0;
// subcode 6= vacation
calendarRule1.Attributes["subcode"] = 6;
// time code 2 = unavailable
calendarRule1.Attributes["timecode"] = 2;
calendarRule1.Attributes["timezonecode"] = -1;
EntityCollection innerCalendarRules = new EntityCollection();
innerCalendarRules.EntityName = "calendarrule";
innerCalendarRules.Entities.Add(calendarRule1);
newInnerCalendar.Attributes["calendarrules"] = innerCalendarRules;
newInnerCalendar.Attributes["calendarid"] = innerCalendarId;
organizationProxy.Update(newInnerCalendar);