create a microsoft outlook add in that allows users to tag an email with a custom field matter id in javascript

To create a Microsoft Outlook Add-in that allows users to tag an email with a custom field Matter ID in JavaScript, follow these steps:

  1. Create a new Outlook Add-in project in Visual Studio. Choose "Office Add-ins" -> "Outlook Web Add-in" template and select JavaScript language.

  2. In the project, open the Manifest.xml file and add a new Context Menu button with a unique id under the MessageComposeCommandSurface section.

    <ExtensionPoint xsi:type="MessageComposeCommandSurface">
        <OfficeTab id="TabDefault">
            <Group id="msgComposeDemoGroup">
                <Label resid="groupLabel" />
                <!-- Add a control for a menu button. -->
                <Control xsi:type="Menu" id="msgComposeDemoMenu">
                    <Label resid="menuLabel" />
                    <Supertip>
                        <Title resid="menuTitle" />
                        <Description resid="menuToolTip" />
                    </Supertip>
                    <Icon>
                        <bt:Image size="16" resid="icon1_32x32" />
                        <bt:Image size="32" resid="icon1_32x32" />
                        <bt:Image size="80" resid="icon1_32x32" />
                    </Icon>
                    <Items>
                        <Item id="customTag">
                            <Label resid="customTagLabel" />
                            <Supertip>
                                <Title resid="customTagTitle" />
                                <Description resid="customTagToolTip" />
                            </Supertip>
                            <Icon>
                                <bt:Image size="16" resid="icon1_32x32" />
                                <bt:Image size="32" resid="icon1_32x32" />
                                <bt:Image size="80" resid="icon1_32x32" />
                            </Icon>
                        </Item>
                    </Items>
                    <ShowOnMenu>false</ShowOnMenu>
                </Control>
            </Group>
        </OfficeTab>
    </ExtensionPoint>
    
    1501 chars
    36 lines
  3. In the project, open the Home.html file and add a form to define the custom field control with input field for Matter ID.

    <form>
        <div>
            <input type="text" id="matterId" placeholder="Enter Matter ID" />
        </div>
        <br />
        <button id="saveMatterId" class="button">Save</button>
    </form>
    
    180 chars
    8 lines
  4. In the project, open the Home.js file and add a function to execute when the custom menu button is clicked.

    index.tsx
    function onCustomTagClicked(event) {
        Office.context.mailbox.item.displayNewForm('IPM.Note', {
            customProperties: {
                MatterId: event.target.value
            }
        });
    }
    
    187 chars
    8 lines
  5. Attach an event listener to the custom menu button to invoke onCustomTagClicked function.

    index.tsx
    function addCustomTagClickListener() {
        var customTagButton = document.getElementById('customTag');
        customTagButton.addEventListener('click', onCustomTagClicked);
    }
    
    172 chars
    5 lines
  6. In the project, open the App.js file and call the addCustomTagClickListener() function on startup.

    index.tsx
    Office.initialize = function () {
        addCustomTagClickListener();
    };
    
    70 chars
    4 lines

That's it! Now the add-in allows users to tag an email with a custom field Matter ID. The Matter ID value is saved as custom property in the email object and can be retrieved and used in other parts of the add-in or integrated with other systems.

gistlibby LogSnag