Share via


Create a Project Task

You can create a Project Task object and link it to a Business Project object.

The following C# and Visual Basic for Applications (VBA) examples show how to create a project task linked to an Account object.

C#

  public void CreateProjectTask()
        {
            Outlook.ApplicationClass _app = new Outlook.ApplicationClass();
            Outlook.Application olApp = (Outlook.Application)_app;
            Outlook.NameSpace olNameSpace = _app.GetNamespace("MAPI");
            Outlook.Folders folders = olNameSpace.Session.Folders;

            Outlook.Folder bcmRootFolder = (Outlook.Folder)folders["Business Contact Manager"];
            Outlook.Folder bcmAccountsFldr = (Outlook.Folder)bcmRootFolder.Folders["Accounts"];
            Outlook.Folder bcmProjFolder = (Outlook.Folder)bcmRootFolder.Folders["Business Projects"];
            
            Outlook.ContactItem newAcct = (Outlook.ContactItem)bcmAccountsFldr.Items.Add("IPM.Contact.BCM.Account");
            newAcct.FullName = "Wide World Importers";
            newAcct.FileAs = "Wide World Importers";
            newAcct.Save();

            Outlook.TaskItem newProject = (Outlook.TaskItem)bcmProjFolder.Items.Add("IPM.Task.BCM.Project");
            newProject.Subject = "Project";

            if (newProject.UserProperties["Parent Entity EntryID"] == null)
            {
                Outlook.UserProperty userProp = newProject.UserProperties.Add("Parent Entity EntryID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = newAcct.EntryID;
            }

            newProject.Save();

            Outlook.Folder bcmProjectTasksFolder = (Outlook.Folder)bcmProjFolder.Folders["Project Tasks"];

            Outlook.TaskItem newProjectTask = (Outlook.TaskItem)bcmProjectTasksFolder.Items.Add("IPM.Task.BCM.ProjectTask");
            newProjectTask.Subject = "Task 1 for Sales Project with Wide World Importers";

            if (newProjectTask.UserProperties["Parent Entity EntryID"] == null)
            {
                Outlook.UserProperty userProp = newProjectTask.UserProperties.Add("Parent Entity EntryID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
                userProp.Value = newProject.EntryID;
            }

            newProjectTask.Save();
        }


VBA

  Sub CreateProjectTask()

    Dim olApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim bcmRootFolder As Outlook.Folder
    Dim olFolders As Outlook.Folders
    Dim bcmAccountsFldr As Outlook.Folder
    Dim bcmProjectsFolder As Outlook.Folder
    Dim bcmProjectTasksFolder As Outlook.Folder
    Dim existAcct As Outlook.ContactItem
    Dim newProject As Outlook.TaskItem
    Dim newProjectTask As Outlook.TaskItem
    Dim userProp As Outlook.UserProperty

    Set olApp = CreateObject("Outlook.Application")
    Set objNS = olApp.GetNamespace("MAPI")
    Set olFolders = objNS.Session.Folders

    Set bcmRootFolder = olFolders("Business Contact Manager")
    Set bcmAccountsFldr = bcmRootFolder.Folders("Accounts")

    Set newAcct = bcmAccountsFldr.Items.Add("IPM.Contact.BCM.Account")
    newAcct.FullName = "Wide World Importers"
    newAcct.FileAs = "Wide World Importers"
    newAcct.Email1Address = "someone@example.com"
    newAcct.Save

    Set bcmProjFolder = bcmRootFolder.Folders("Business Projects")

    Set newProject = bcmProjFolder.Items.Add("IPM.Task.BCM.Project")
    newProject.Subject = "Sales Project with Wide World Importers"

    If (newProject.UserProperties("Source of Lead") Is Nothing) Then
        Set userProp = newProject.UserProperties.Add("Parent Entity EntryID", olText, False, False)
        userProp.Value = newAcct.EntryID
    End If

    newProject.Save

    Set bcmProjectTasksFolder = bcmProjFolder.Folders("Project Tasks")
    Set newProjectTask = bcmProjectTasksFolder.Items.Add("IPM.Task.BCM.ProjectTask")
    newProjectTask.Subject = "Task 1 for Sales Project with Wide World Importers"

    If (newProjectTask.UserProperties("Source of Lead") Is Nothing) Then
        Set userProp = newProjectTask.UserProperties.Add("Parent Entity EntryID", olText, False, False)
        userProp.Value = newProject.EntryID
    End If
    
    newProjectTask.Save

    Set newProject = Nothing
    Set newProjectTask = Nothing
    Set existAcct = Nothing
    Set bcmAccountsFldr = Nothing
    Set bcmProjectsFolder = Nothing
    Set bcmProjectTasksFolder = Nothing
    Set olFolders = Nothing
    Set bcmRootFolder = Nothing
    Set objNS = Nothing
    Set olApp = Nothing

End Sub  

See Also

Select a Project Task | Edit a Project Task | Delete a Project Task | 2007 Office System: Updated Developer Content