Jump to content

Need Help With _OutlookGetTasks Function


Recommended Posts

Trying to figure out how to get the OUTLOOK UDF function _OutlookGetTasks to return ONLY "Not Started" tasks from Outlook 2003. If I run it this way:

$OutlookTaskArray = _OutlookGetTasks($oOutlook,"","","","","OutlookWarning2.exe")

215 tasks from Outlook are returned - representing ALL tasks of ANY "Status".

If I'm reading the example correctly, if you run it this way:

$OutlookTaskArray = _OutlookGetTasks($oOutlook,"","","",0,"OutlookWarning2.exe")

It appears that this should return ONLY "Not Started" tasks - but it doesn't seem to work. It simply returns ALL 215 tasks again - regardless of their "Status"- just like the first example.

When I tried to return only "Complete" tasks using:

$OutlookTaskArray = _OutlookGetTasks($oOutlook,"","","",2,"OutlookWarning2.exe")

No records are returned... Even though the data from the first query above clearly shows that there are records with STATUS=0 (Not Started) and STATUS=2 (Complete) in the recordset.

I realize that I could write code to filter these items by testing element [1][3] of the array... But I'm really interested in finding out if I'm somehow not using the OUTLOOK UDF properly. Any suggestions?

Link to comment
Share on other sites

Tip: If you're using a non-standard UDF include a link to avoid confusion.

The UDF always worked fine for me using office 2003, but started to act up using office 2007 and 2010, so I think it might need to be reviewed. (what version are you using?)

There does seem to be another reason for the behavior you describe though:

The standard value for $sStatus is "" which autoit evaluates as "", 0, or False.

Setting the value to 0, will make the function think no value is set and it will not be added to the filter string.

I changed the function a bit to overcome this, but I expect there are more problems with it, so to get the results you want I suppose you could discard the status and just filter the returned array yourself.

adjusted function (untested):

;===============================================================================
;
; Function Name:    _OutlookGetTasks()
; Description:  Get the Tasks in Microsoft Outlook, specify Subject and/or Date Interval and/or Status to filter
; Syntax.........: _OutlookGetTasks($oOutlook, $sSubject = "", $sStartDate = "", $sEndDate = "", $sStatus = "", $sWarningClick = "")
; Parameter(s):     $oOutlook           - Outlook object opened by a preceding call to _OutlookOpen().
;                   $sSubject   - Optional: The Subject of the Task.
;                   $sStartDate         - Optional: Start date & time of the Task, format YYYY-MM-DD HH:MM - or what is set locally.
;                   $sEndDate           - Optional: End date & time of the Task, format YYYY-MM-DD HH:MM - or what is set locally.
;                   $sStatus            - Optional: The status of the Task:
;                                    $olTaskNotStarted=0
;                                    $olTaskInProgress=1
;                                    $olTaskComplete=2
;                                    $olTaskWaiting=3
;                                    $olTaskDeferred=4
;   $sWarningClick      - Optional: The Entire SearchString to 'OutlookWarning2.exe', Default = None
; Requirement(s): AutoIt3 with COM support (post 3.1.1)
; Return Value(s):  On Success      - Array in the following format: [1000][6]
;                                    [0][0] - Number of items
;                                    [0][1] - Number of items not started
;                                    [1][0] - Subject
;                                    [1][1] - StartDate
;                                    [1][2] - EndDate
;                                    [1][3] - sStatus
;                                    [1][4] - Priority
;                                    [1][5] - Complete
;                                    [1][6] - PercentComplete
;                                    [1][7] - ReminderSet
;                                    [1][8] - ReminderMinutesBeforeStart
;                                    [1][9] - Owner
;                                    [1][10] - Body
;                                    [1][11] - Date Completed
;                                    [1][12] - Total Work in minutes
;                                    [1][13] - Actual work in minutes
;                                    [1][14] - Mileage
;                                    [1][15] - Billing Information
;                                    [1][16] - Companies
;                                    [1][17] - Delegator
;                                    [1][18] - Categories
;                                    [n][n] - Item n
;   On Failure  - Returns 0 and sets @ERROR > 0
;                   @ERROR = 1      - Illegal parameters 
;                   @ERROR = 2      - No tasks found
;                   @ERROR = 3      - More than 999 Tasks found, the first 999 tasks will be returned.
;                   @ERROR = 9  - ObjEvent error.
; Author(s):    Wooltown
; Created:  2009-03-02
; Modified:     -
;
;===============================================================================
Func _OutlookGetTasks($oOutlook, $sSubject = "", $sStartDate = "", $sEndDate = "", $sStatus = -1, $sWarningClick = "")
    If $sWarningClick <> "" And FileExists($sWarningClick) = 0 Then
        Return SetError(2, 0, 0)
    Else
        Run($sWarningClick)
    EndIf
    Local $avTasks[1000][19], $sFilter = "", $oFilteredItems
    Local $oOuError = ObjEvent("AutoIt.Error", "_OutlookError")
    $avTasks[0][0] = 0
    $avTasks[0][1] = 0
    Local $oNamespace = $oOutlook.GetNamespace("MAPI")
    Local $oFolder = $oNamespace.GetDefaultFolder($olFolderTasks)
    Local $oColItems = $oFolder.Items
    $oColItems.Sort("[Start]")
    $oColItems.IncludeRecurrences = True 
    If $sSubject <> "" Then
        $sFilter = '[Subject] = "' & $sSubject & '"'
    EndIf
    If $sStartDate <> "" Then
        If Not _DateIsValid($sStartDate) Then Return SetError(1, 0, 0)
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[Start] >= "' & $sStartDate & '"'
    EndIf   
    If $sEndDate <> "" Then
        If Not _DateIsValid($sEndDate) Then Return SetError(1, 0, 0)
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[Due] <= "' & $sEndDate & '"'
    EndIf   
    If $sStatus <> -1 Then
        If $sFilter <> "" Then $sFilter &= ' And '
        $sFilter &= '[Status] = "' & $sStatus & '"'
    EndIf
    If $sFilter = "" Then
        $oFilteredItems = $oColItems
    Else
        $oFilteredItems = $oColItems.Restrict($sFilter)
    EndIf
    For $oItem In $oFilteredItems
            If $avTasks[0][0] = 999 Then
                SetError (3)
                Return $avTasks
            EndIf
            $avTasks[0][0] += 1
            $avTasks[$avTasks[0][0]][0] = $oItem.Subject
            $avTasks[$avTasks[0][0]][1] = $oItem.StartDate
            $avTasks[$avTasks[0][0]][2] = $oItem.DueDate
            $avTasks[$avTasks[0][0]][3] = $oItem.Status
            $avTasks[$avTasks[0][0]][4] = $oItem.Importance
            $avTasks[$avTasks[0][0]][5] = $oItem.Complete
            $avTasks[$avTasks[0][0]][6] = $oItem.PercentComplete
            If $avTasks[$avTasks[0][0]][6] = 0 Then $avTasks[0][1] += 1
            $avTasks[$avTasks[0][0]][7] = $oItem.ReminderSet
            $avTasks[$avTasks[0][0]][8] = $oItem.ReminderTime
            $avTasks[$avTasks[0][0]][9] = $oItem.Owner
            $avTasks[$avTasks[0][0]][10] = $oItem.Body
            $avTasks[$avTasks[0][0]][11] = $oItem.DateCompleted
            $avTasks[$avTasks[0][0]][12] = $oItem.TotalWork
            $avTasks[$avTasks[0][0]][13] = $oItem.ActualWork
            $avTasks[$avTasks[0][0]][14] = $oItem.Mileage
            $avTasks[$avTasks[0][0]][15] = $oItem.BillingInformation
            $avTasks[$avTasks[0][0]][16] = $oItem.Companies
            $avTasks[$avTasks[0][0]][17] = $oItem.Delegator
            $avTasks[$avTasks[0][0]][18] = $oItem.Categories
    Next
    $oItem = ""
    $oColItems = ""
    $oFolder = ""
    $oNamespace = ""
    If $avTasks[0][0] = 0 Then Return SetError(2, 0, 0)
    Redim $avTasks[$avTasks[0][0] + 1][19]
    Return $avTasks
EndFunc

edit: "adjsuted" is not a word.

Edited by Tvern
Link to comment
Share on other sites

Thanks for the info. As noted, I am using Outlook 2003. But, more specifically, v11.8313.8324 SP3. I know I used this function quite a bit when it was originally developed - and I don't recall having this issue. So perhaps something changed when SP3 for Office 2003 was applied? Not sure. In any event, since you've seen issues with the "newer" versions of Office - I'll go ahead and do the filtering in my own script - just in case I end up upgrading Office soon. I appreciate the info.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...