Share via


Create a Business Project linked to a Primary Business Contact

Outlook Developer Reference
Create a Business Project linked to a Primary Business Contact

You can create a Business Project object and link it to one or more Business Contact objects, but the business project can have only one primary Business Contact. If linked with a Business Contact, the History section of the Business Contact form displays details of the project and the Link To field on the Business Project form displays the Business Contact name.

The following C# and Visual Basic for Applications (VBA) examples show how to create a new business project and link it to a new Business Contact object.

  private void CreateBusinessProjectWithBusinessContact()
        {
            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 contacts = (Outlook.Folder)bcmRootFolder.Folders["Business Contacts"];
        
        Outlook.ContactItem newContact =
        (Outlook.ContactItem)contacts.Items.Add("IPM.Contact.BCM.Contact");

        newContact.FullName = "John Smith";
        newContact.FileAs = "John";
        newContact.Save();

        string contactEntryID = newContact.EntryID;

        Outlook.Folder projects = (Outlook.Folder)bcmRootFolder.Folders["Business Projects"];
        Outlook.TaskItem newProjects =
        (Outlook.TaskItem)projects.Items.Add("IPM.Task.BCM.Opportunity");
        newProjects.Subject = "Sales Opp with John Smith";

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

    }
  Sub CreateBusinessProjectWithBusinessContact()

Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim olFolders As Outlook.Folders Dim bcmRootFolder As Outlook.Folder Dim bcmContactsFldr As Outlook.Folder Dim newContact As Outlook.ContactItem Dim newProject As Outlook.TaskItem

Set olApp = CreateObject("Outlook.Application") Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders Set bcmRootFolder = olFolders("Business Contact Manager") Set bcmContactsFldr = bcmRootFolder.Folders("Accounts") Set bcmProjFolder = bcmRootFolder.Folders("Business Projects")

Set newContact = bcmContactsFldr.Items.Add("IPM.Contact.BCM.Contact") newContact.FullName = "John Smith" newContact.FileAs = "John Smith" newContact.Email1Address = "someone@example.com" newContact.Save

Set newProject = bcmProjFolder.Items.Add("IPM.Task.BCM.Project") newProject.Subject = "Project For Wide World Importers to enter into Retail Field"

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

newProject.Save

Set newProject = Nothing Set newContact = Nothing Set bcmProjFolder = Nothing Set bcmContactssFldr = Nothing Set bcmRootFolder = Nothing Set olFolders = Nothing Set objNS = Nothing Set olApp = Nothing

End Sub

See Also

Select a Business Project | Edit a Business Project | Delete a Business Project | Create a Business Project linked to a Primary Account | Office Developer Center: Outlook 2007