locked
calendar and holidays RRS feed

  • Question

  • Hi all
        In CRM 4.0 how to check programatically if '2009-04-16' (or any other day) is a holiday? I have only organization ID but holidays aren't on systemuser level like vacations so I think it is enough. Is it possible?

    Kind regards,
    Jerzy D.
    everything is a matter of probability...
    Thursday, April 16, 2009 2:23 PM

Answers

  • Jerzy,

    I thought I would provide you with more guidance on that topic. You can use the following pseudocode to solve your issue:

    // create your service first - I assume you have it
    
    // get your organization
    WhoAmIRequest res = new WhoAmIRequest();
    WhoAmIResponse res = (WhoAmIResponse)crmService.Execute(res);
    
    Guid orgGuid = res.OrganizationId;
    
    organization orgDetails = (organization)crmService.Retrieve(EntityName.organization.ToString()), new AllColumns());
    Guid calendarGuid = orgDetails.bussinessclosurecalendarid.Value;
    
    calendar yourCalendar = (calendar)crmService.Retrieve(EntityName.calendar.ToString(), calendarGuid, new AllColumns());
    
    foreach(calendarrule cr in yourCalendar.calenarrules)
    {
        // check your date against e.g. the cr.starttime.date
        // if the dates are equal, then your date '2009-04-16' is a holiday!
    }
    I hope that clarifies :).

    Kind regards,
    Kuba
    -- Kuba Skałbania, Netwise
    Thursday, April 16, 2009 4:48 PM

All replies

  • Hi Jerzy,

    Use the businessclosurecalendarid property of the organization class (provided that you have you organization data retrieved) to get the GUID of the Business Closures calendar. Then check the calendarrules array to get the rules of this particular calendar. You may then iterate through them to check whether the particular date is there.

    I hope that helps,
    Kuba
    -- Kuba Skałbania, Netwise
    Thursday, April 16, 2009 4:12 PM
  • Jerzy,

    I thought I would provide you with more guidance on that topic. You can use the following pseudocode to solve your issue:

    // create your service first - I assume you have it
    
    // get your organization
    WhoAmIRequest res = new WhoAmIRequest();
    WhoAmIResponse res = (WhoAmIResponse)crmService.Execute(res);
    
    Guid orgGuid = res.OrganizationId;
    
    organization orgDetails = (organization)crmService.Retrieve(EntityName.organization.ToString()), new AllColumns());
    Guid calendarGuid = orgDetails.bussinessclosurecalendarid.Value;
    
    calendar yourCalendar = (calendar)crmService.Retrieve(EntityName.calendar.ToString(), calendarGuid, new AllColumns());
    
    foreach(calendarrule cr in yourCalendar.calenarrules)
    {
        // check your date against e.g. the cr.starttime.date
        // if the dates are equal, then your date '2009-04-16' is a holiday!
    }
    I hope that clarifies :).

    Kind regards,
    Kuba
    -- Kuba Skałbania, Netwise
    Thursday, April 16, 2009 4:48 PM
  • Thank you :] I missed somehow businessclosurecalendarid attribute but now it is clear. One more question. I tried to use this calendar ID in expandcalendar message but every time I get error that timezone code is invalid. Value of 'start' attribute in expandcalendar message is '2009-04-17T00:00:00+02:00' (before that tried '2009-04-17T00:00:00+0200' with the same result) , 'end' attribute have the same format. It works when I run expandcalendar with different calendar IDs.

    EDIT:
    Forgot about question... Is it possible to use this calendar in expandcalendar message?
    Friday, April 17, 2009 7:27 AM

  • WhoAmIRequest res = new WhoAmIRequest();

    WhoAmIResponse res = (WhoAmIResponse)crmService.Execute(res);



    Guid orgGuid = res.OrganizationId;



    organization orgDetails = (organization)crmService.Retrieve(EntityName.organization.ToString()), new AllColumns());

    Guid calendarGuid = orgDetails.bussinessclosurecalendarid.Value;



    calendar yourCalendar = (calendar)crmService.Retrieve(EntityName.calendar.ToString(), calendarGuid, new AllColumns());




    Hi, everybody...

    I have the same question... I have to set specific days of the year as vacation days.
    What should i do after i have retrieved calendar yourCalendar  object.

    Or in my case i have to do it in another way?

    Thanks
    Monday, July 20, 2009 10:12 AM