Community
Showing results for 
Search instead for 
Do you mean 
Reply

Retrieving Single Activity Instances By ID

New Member
Posts: 31
Country: USA

Retrieving Single Activity Instances By ID

Hi Everyone,

I am trying to retrieve single activity instances by using an ID and I seem to retrieve the whole reoccurring series.
For example, I retrieve the activities using an array of activity ID's using the call below:


Dim Group_Activities() As System.Guid

ReDim Group_Activities(0)= New System.Guid(strActivityID1)
ReDim Preserve Group_Activities(1)= New System.Guid(strActivityID2)
ReDim Preserve Group_Activities(2)= New System.Guid(strActivityID3)

ActivityList = ACTFM.Activities.GetActivityInstancesByActivityId(Group_Activities)

Where strActivityID1, 2 and 3 are three different Activity ID's

THE PROBLEM here is that all reoccuring instances of the activities are expanded when you retrieve them and cause quite a significant delay in the retrieval of the activity. For example, if strActivityID1 is a daily reoccurence, you'll get a list that is probably over 20,000 long with the same activity but a different date.

What I want is to retrieve the three activities by ID without the long reoccuring list. Does anyone know how to do this. I checked all the documented calls, including the ACTFM.Activities.GetTaskListItems call but with no luck.
Will this involve creating (to my dread) a long list of filter items to pass a parameter to the GetTaskListItems?
If so, how does one create this filter? Also, are there any limitations on how long the filter string can be?

Thank you in advance.
Copper Contributor
Posts: 98
Country: United States

Re: Retrieving Single Activity Instances By ID

[ Edited ]
Code Snippet I found in one of my old projects.
 
I hope it helps
 
Code:
            ActivityList allActivities = ActFwk.Activities.GetTaskListItems(
                aSort,          //Any Sort Criteria 
                aFilter,           //Any Filters
                startRange,     //Minimum allowed start date
                endRange,       //Maximum allowed start date
                FirstInstanceRestriction.FirstUnclearedOccurrence,  //Important - we only need the first uncleared occurrence 
                true           // relic - not even used anymore - can be true or false.
                );

 
 
I think its important to note that you are probably going to want to filter on AccessorID at some point to only get the current user's Activities and not get each active occurance from each user in the database.
 
 
 
 
 
 
 
Expanded Examples from Code Samples.chm for reference
 
Code:
[Visual Basic]

Public Function GetTaskListItems( _
   ByVal sortCriteria As ActivitySortCriteria, _
   ByVal filterCriteria As IActivityFilterCriteria, _
   ByVal startRange As Date, _
   ByVal endRange As Date, _
   ByVal showFirstRestiction As FirstInstanceRestriction, _
   ByVal deferInitialLoad As Boolean _
) As ActivityList

'Example 1
Dim aList As ActivityList
Dim sortCriteria As ActivitySortCriteria
Dim filterCriteria As IActivityFilterCriteria
Dim startDate As DateTime
Dim endDate As DateTime
Dim showFirstRestiction As FirstInstanceRestriction
Dim deferInitialLoad As Boolean
.
.
.
aList = ActFwk.Activities.GetTaskListItems(sortCriteria, filterCriteria, startRange, endRange, showFirstRestiction, deferInitialLoad)

'Example 2
'This example retrieves all the activities.
'This is equivalent to setting the tasklist filters in ACT! to show all.
'Create the sort criteria
Dim occurDate As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.OccurDate)
Dim aSort As ActivitySortCriteria = New ActivitySortCriteria(occurDate, ListSortDirection.Ascending)
'Get the filter criteria
Dim adfc() As ActivityDateFilterCriteria = New ActivityDateFilterCriteria() {New ActivityDateFilterCriteria(occurDate, ActFwk.Activities.MIN_SMALL_DATE_TIME, ActFwk.Activities.MAX_SMALL_DATE_TIME)}
'Populate an ActivityList with Activities.
Dim aList As ActivityList = ActFwk.Activities.GetTaskListItems(aSort, adfc, ActFwk.Activities.MIN_SMALL_DATE_TIME, ActFwk.Activities.MAX_SMALL_DATE_TIME, FirstInstanceRestriction.FirstUnclearedOccurrence, False)
If Not (aList Is Nothing) Then
    MessageBox.Show(aList.Count.ToString())
Else
    MessageBox.Show("The ActivityList was Nothing.")
End If

'Example 3
'The tasklist in ACT! provides eight different filters:
'Dates, Types, Priorities, Select Users, Show Private,
'Only Show Timeless, Show Cleared Tasks, and Show Outlook Tasks.
'This routine provides an example of how to mimic that behavior.

'Sort Criteria.
'We'll setup our sort object ahead of time for later use.
'This well be used when we make the call to GetTaskListItems.
'GetTaskListItems is the method we call that retrieves the activities.
'The sort order will be ascending on the occurance date field.
'This is the default tasklist sort order in ACT!.
'Imports Act.Framework.Users
Dim afdSortField As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.OccurDate)
Dim lsd As ListSortDirection
lsd = ListSortDirection.Ascending
Dim aSort As ActivitySortCriteria = New ActivitySortCriteria(afdSortField, lsd)

'An ArrayList to collect filter criteria.
'We'll later cast this to an array of IActivityFilterCriteria.
Dim alCriteria As ArrayList = New ArrayList
'An ArrayList for temporary use.
Dim alTemp As ArrayList = New ArrayList

'ActivityFieldDescriptors that we'll use.
'For filtering a date range.
Dim afdOccurDate As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.OccurDate)
'For filtering activity types.
Dim afdTypeId As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.TypeId)
'For filtering activity priorities.
Dim afdPriorityId As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.PriorityId)
'For filtering users.
Dim afdAccessorId As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.AccessorId)
'In ACT! you find these next four filters on the Tasklist's Options button.
'For filtering private activities.
Dim afdIsPrivate As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.IsPrivate)
'For the Show Only Timeless option.
Dim afdIsTimeless As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.IsTimeless)
'For showing cleared activities.
Dim afdIsCleared As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.IsCleared)
'For showing Outlook activities.
Dim afdSourceId As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.SourceId)
'For eleminating events.
Dim afdIsEvent As ActivityFieldDescriptor = New ActivityFieldDescriptor(ActivityField.IsEvent)

'A selection of variables we'll use to select our criteria.
'The start and end date criteria for our date filter.
Dim StartDate As DateTime
Dim EndDate As DateTime
'This will be used to determine whether or not to featch activity types that have been set to inactive.
Dim bIncludeInactiveTypes As Boolean
'This will be used to determine whether or not to featch priorities that have been set to inactive.
Dim bReturnOnlyActivePriorities As Boolean
'Hopefully the names of these variables are self explanitory.
Dim bShowClearedTasks As Boolean
Dim bShowPrivate As Boolean
Dim bOnlyShowTimeless As Boolean
Dim bShowOutlookTasks As Boolean

'Temp variable for loops.
Dim i As Integer

'Here we set the options for our filters.
StartDate = DateTime.Parse("01/01/2006 00:00:00")
EndDate = DateTime.Parse("12/31/2006 23:59:59")
bIncludeInactiveTypes = True
bReturnOnlyActivePriorities = False
bShowClearedTasks = True
bShowPrivate = True
bOnlyShowTimeless = False
bShowOutlookTasks = True

'Since we don't have a gui interface in this example to make
'selections from we include all the types, priorities, and users.
Dim ats() As ActivityType = ActFwk.Activities.GetActivityTypes(bIncludeInactiveTypes)
Dim aps() As ActivityPriority = ActFwk.Activities.GetActivityPriorities(bReturnOnlyActivePriorities)
Dim uUsers() As User = ActFwk.Users.Users

'Now it's time to start collecting our filter criteria into our ArrayList (alCriteria).
'Date range.
Dim adfcDateRange As ActivityDateFilterCriteria = New ActivityDateFilterCriteria(afdOccurDate, StartDate, EndDate)
alCriteria.Add(adfcDateRange)

'Types.
alTemp.Clear()
For i = 0 To ats.Length - 1
    alTemp.Add(ats(i).ActivityTypeId)
Next i
Dim iATypes() As Integer = alTemp.ToArray(GetType(Integer))
Dim aifcTypes As ActivityInFilterCriteria = New ActivityInFilterCriteria(afdTypeId, iATypes)
alCriteria.Add(aifcTypes)

'Priorities.
alTemp.Clear()
For i = 0 To aps.Length - 1
    alTemp.Add(aps(i).Id)
Next i
Dim iPriorities() As Integer = alTemp.ToArray(GetType(Integer))
Dim aifcPriorities As ActivityInFilterCriteria = New ActivityInFilterCriteria(afdPriorityId, iPriorities)
alCriteria.Add(aifcPriorities)

'Users.
alTemp.Clear()
For i = 0 To uUsers.Length - 1
    alTemp.Add(uUsers(i).ID)
Next i
Dim gUsers() As Guid = alTemp.ToArray(GetType(Guid))
Dim aifcUsers As ActivityInFilterCriteria = New ActivityInFilterCriteria(afdAccessorId, gUsers)
alCriteria.Add(aifcUsers)

'Private.
If (bShowPrivate) Then
    Dim acfcPrivate As ActivityComparisonFilterCriteria = New ActivityComparisonFilterCriteria(afdIsPrivate, ComparisonFilterCriteria.Operation.GreaterThanOrEqual, "0")
    alCriteria.Add(acfcPrivate)
End If

'Timeless.
If (bOnlyShowTimeless) Then
    Dim acfcTimeless As ActivityComparisonFilterCriteria = New ActivityComparisonFilterCriteria(afdIsTimeless, ComparisonFilterCriteria.Operation.GreaterThanOrEqual, "1")
    alCriteria.Add(acfcTimeless)
End If

'Cleared.
If Not (bShowClearedTasks) Then
    Dim acfcCleared As ActivityComparisonFilterCriteria = New ActivityComparisonFilterCriteria(afdIsCleared, ActivityComparisonFilterCriteria.Operation.Equals, 0)
    alCriteria.Add(acfcCleared)
End If

'Outlook.
If Not (bShowOutlookTasks) Then
    alCriteria.Add(New ActivityComparisonFilterCriteria(afdSourceId, ComparisonFilterCriteria.Operation.NotEqual, ActivityRecordSource.OutlookAppointment))
    alCriteria.Add(New ActivityComparisonFilterCriteria(afdSourceId, ComparisonFilterCriteria.Operation.NotEqual, ActivityRecordSource.OutlookTask))
End If

'ACT! does not display events on its tasklist, so we'll add this extra filter to eliminate events.
Dim acfcEvent As ActivityComparisonFilterCriteria = New ActivityComparisonFilterCriteria(afdIsEvent, ActivityComparisonFilterCriteria.Operation.Equals, 0)
alCriteria.Add(acfcEvent)

'Now we'll cast our ArrayList containing our filter criteria to an
'array of IActivityFilterCriteria for use in the call to GetTaskListItems.
'Note: Notice that we create our IActivityFilterCriteria array with one less
'element than alCriteria.Count, but we still get the same number of elements
'as alCriteria.Count. I beleive this is a bug in vb.net. If we create the
'IActivityFilterCriteria array with alCriteria.Count elements we end up with
'one to many and will get a runtime error during the call to GetTaskListItems.
Dim afcFilter(alCriteria.Count - 1) As IActivityFilterCriteria
alCriteria.CopyTo(afcFilter)

'And fetch the activities.
Dim aList As ActivityList = ActFwk.Activities.GetTaskListItems(aSort, afcFilter, StartDate, EndDate, FirstInstanceRestriction.FirstUnclearedOccurrence, False)

'Show how many activities are in our ActivityList.
If Not (aList Is Nothing) Then
    MessageBox.Show(aList.Count.ToString())
Else
    MessageBox.Show("The ActivityList is Nothing")
End If

 




Message Edited by Carlton_Jones on 04-03-2008 11:32 AM
Carlton Jones
Sage Software
New Member
Posts: 31
Country: USA

Re: Retrieving Single Activity Instances By ID

Thanx. I'll try that.

T