1
我希望做如下(我使用.NET 4.5,在线CRM-2015)时间过使用C#(插件或其他方式)
- 一个特别的设备和设施资源可能无法在在线CRM 2015年进入在特定日期可用于安排
- 这是通过代码通过插件或简单的Web应用程序中的C#完成的
- 用户将选择设备/设施,时间(s)关闭。
- 在资源不应用于任何服务活动(通过CRM UI中的服务日历)的选定日期。
我已经写过这段代码了。代码是copied from the internet。
// 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用户界面执行相同的操作,则会在休息日显示红色标记,在我的情况下不会显示任何提示。
- 对于同一设施创建此记录后,我无法更改工作时间。
- 在设置 - >服务管理 - >假日计划下。我可以看到没有任何名称的新记录,但是当我尝试打开相同记录时,它会提供CRM错误。您也不能删除此记录
- 一旦我删除日历规则(通过代码),然后我可以返回到服务管理 - >假日计划并删除记录,一旦完成,我可以更改工作时间设施。
您能告诉我我做错了什么,以及如何编写代码来安排设施和设备的时间。
AFAIK这整个时间过的事情可以通过OOB功能的设置,我可能会被误读,但似乎你可以使用OOB为此,不需要任何定制 – Alex
亚历嗨,不幸的是,OOB路径是不是选项,因为它必须通过外部门户完成 – Sudeep