How-to add a contact in outlook.com from a canvas app

Adding a contact from a canvas app to outlook.com is perhaps not as straightforward as you would expect. Below, code is shown which adds a contact to outlook.com.

A connection to outlook.com needs to be created before this code will work.

The ContactPostItem action is used to add a contact. The first parameter is the folder where you want to add the contact to. The second parameter is the “GivenName” of the contact. The third parameter is a table for “HomePhones”. This parameter can be empty where empty means: Table({Value: ""}).

The fourth and last parameter contains other contact properties. Some are straightforward and some must be added as a record (The “BusinessAddress” in the example below).

ClearCollect(
    coll_Contact_Record,
    {
        City: "Hometown",
        CountryOrRegion: "The Netherlands",
        PostalCode: "9999 AA",
        Street: "Street 1",
        State: ""
    }
);
ClearCollect(
    coll_Contact_Returns,
    'Outlook.com'.ContactPostItem(
        "Contacts",
        "Rick",
        Table(
            {Value: "0031 11 111 1111"},
            {Value: "0031 22 222 2222"}
        ),
        {
            CompanyName: "Forms and Flows",
            Surname: "Bakker",
            DisplayName: "Rick Bakker",
            MobilePhone1: "0031 6 12345678",
            BusinessAddress: First(coll_Contact_Record)
        }
    )
)

I also noticed that outlook.com does not use the property “DisplayName”. It shows the property “GivenName” followed by the property “Surname”. The Outlook desktop client does use the property “DisplayName”.

When adding an address, you need to add all properties even when some are empty like the “State” in the example.

References

[1] https://docs.microsoft.com/en-us/connectors/outlook/#create-contact

Leave a Reply

Your email address will not be published. Required fields are marked *