gpt4 book ai didi

c# - 使用 C# 仅从 CRM 2015 日历返回假期日期列表

转载 作者:太空宇宙 更新时间:2023-11-03 15:01:56 26 4
gpt4 key购买 nike

我是 CRM 2015 的新手,我想编写连接到 CRM 的 C# 方法,并仅从日历返回假期日期列表,如下所示:

List<DateTime> lst = GetHolidayListFromCRM();
......
public List<DateTime> GetHolidayListFromCRM()
{
IOrganizationService service = GetServiceProxy(USERNAME, PASSWORD, DOMAIN, CRM_URL);

using (OrganizationServiceContext svcContext = new OrganizationServiceContext(service))
{
var info = svcContext.CreateQuery("calendar");
//Some code here for processing and returning only holiday date list
}
}

最佳答案

List<DateTime> ret = new List<DateTime>();

QueryExpression qe = new QueryExpression("calendar");
qe.Criteria.AddCondition("name", ConditionOperator.Equal, "Business Closure Calendar");
EntityCollection ec = service.RetrieveMultiple(qe);

if (ec.Entities.Count != 1) { return ret; }
Entity calendar = ec.Entities[0];
if(!calendar.Contains("calendarrules")) { return ret; }
EntityCollection rules = calendar.GetAttributeValue<EntityCollection>("calendarrules");

foreach (Entity rule in rules.Entities)
{
ret.Add(rule.GetAttributeValue<DateTime>("startime"));
// Console.Out.WriteLine("{0}:{1}", rule["starttime"], rule["name"]);
}

return ret;

注意:无法直接访问日历规则:

  1. http://www.inogic.com/blog/2014/08/calendars-and-expand-calendar-request-in-crm-2013-sp-1/
  2. https://community.dynamics.com/crm/f/117/t/185090
  3. https://msdn.microsoft.com/en-us/library/gg327912.aspx?f=255&MSPPError=-2147217396

关于c# - 使用 C# 仅从 CRM 2015 日历返回假期日期列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45816430/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com