Community
Showing results for 
Search instead for 
Do you mean 
Reply

Rescheduling Activities

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Rescheduling Activities

Hi All,
 
Hope someone can help me since I think I'm loosing my marbles! Smiley Surprised
I am trying to build build what I thought would be a quick 10 minute utility to carry out a simple batch rescheduleWith. We have had a Sales user leave and a new guy has taken over his accounts and so I said (rather stupidly looking back now) "yeah don't worry I should get that done in a couple of mins...". It has now taken me the whole bloomin' morning with no joy! I know I am missing something somewhere!
 
Basically the first problem was the inability to simply pull and ActivityList of Activity for the user. I had to foreach through the entire Activity collection getting the ScheduleFor property. Its inefficient but it was the only way I could come up with, so if anyone can think of a better way please let me know! Smiley Happy
 
The second and more pressing problem now is, I have the ActivityList but how on earth do I reschudleFor? I thought I had seen a method for this but I think I was imagining things now! The ScheduledFor is a read-only property.
 
Hope someone can help.
TIA.
Vivek
Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Employee
Posts: 2
Country: USA

Re: Rescheduling Activities

[ Edited ]
Here is a sample function. The trick is setting the Organizer property on each activity. The sample also illustrates how to retrieve the activities you are interested in (by organizer id).
 
private void RescheduleMyActivities()
{
    Guid origSchedForId = this.actFW.CurrentUser.ID;    // Id of current schedFor user. I used my own for this sample
    // Create a new comparison filter criteria
    ActivityComparisonFilterCriteria scheduleForFilter = new ActivityComparisonFilterCriteria(new ActivityFieldDescriptor(ActivityField.OrganizeUserId), ComparisonFilterCriteria.Operation.Equals, origSchedForId);
   
    // Get min and max date range
    DateTime startRange = this.actFW.Activities.MIN_SMALL_DATE_TIME;
    DateTime endRange = this.actFW.Activities.MAX_SMALL_DATE_TIME;
   
    // Get the activity list
    ActivityList al = this.actFW.Activities.GetActivityList(null, new IActivityFilterCriteria[1] { scheduleForFilter }, startRange, endRange);
   
    // Use the Id of the new schedule-for user (organizer) to get the actual CalendarDelegateGrantor record.
    // I picked one out of the DB for illustration
    Guid newSchedForUserId = new Guid("39B3105D-5EE3-4A62-8F1E-FE054F0546C4"); 
    CalendarDelegateGrantor newSchedForUser = this.actFW.CalendarDelegates.GetCalendarDelegateGrantorByAccessorId(newSchedForUserId);

    // Update them all.
    foreach (Activity a in al)
    {
        a.Organizer = newSchedForUser;
        a.Update();
    }
}


Message Edited by jjones on 03-06-2008 04:50 PM
Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: Rescheduling Activities

Hi JJones,
 
Thanks so much for that! This has been driving me up the wall and my code was becoming so convoluted and I found myself going round in circles. Your method is much more straightforward.
 
I have to admit that working with the SDK especially when it comes to secondary entities is like doing cryptic crosswords! Once you get into the warped and twisted mindset of the entity devs its kind of makes sense! Smiley Tongue
 
For me the key things were the
ActivityComparisonFilterCriteria()
IActivityFilterCriteria()
Organizer
I was going off and using the inherited ActivityFilterCriteria methods and was even going into the FieldDescriptor Collection to iterate through...yuck! Smiley Surprised
 
Cheers,
Vivek
Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Employee
Posts: 2
Country: USA

Re: Rescheduling Activities

You're welcome - I hope it helps out!