我是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
}
}
答案 0 :(得分:0)
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;
注意:无法直接访问日历规则: