web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :

Dynamics 365 scripting issues with App for Outlook (ES6 vs IE11)

Arun Vinoth Profile Picture Arun Vinoth 11,615 Moderator
Learning: Dynamics 365 App for Outlook uses classic IE as rendering engine. Hence the script using ES6 standard is not compatible. We have to rewrite using ES5 standard to make our script work in AFO. Chrome & Edge are modern browsers and they are fine with ES6 standards like ARROW function in callback, namespace & "this" operator, etc.

Examples:

1. Below is self explanatory, always use semicolon at the end of container
namespace = {
    formContext: null,

    initial: function (executionContext) { // entry function
        this.formContext = executionContext.getFormContext();
	}
};
2. Arrow functions inside Promise like success callback & "this" operator replaced with namespace name
	    //ES6 standard	
            var uri = "?$select=_businessunitid_value";
            Xrm.WebApi.retrieveRecord("systemuser", Xrm.Utility.getGlobalContext().userSettings.userId.substring(1, 37), uri)
           .then(
                (success) => { //Arrow function works fine in ES6
                    if (success["_businessunitid_value@OData.Community.Display.V1.FormattedValue"] === "expected BU") {

                        if (this.formContext.ui.getFormType() === 1) { //"this" works fine in ES6
                        }
                    }
                },
                (error) => { //Arrow function works fine in ES6
                }
           );
Above code works fine in Chrome, Edge & UCI app. But fail in IE11 as well as App for Outlook. The below code remediation will work fine.
	//ES5 standard
        var uri = "?$select=_businessunitid_value";
        Xrm.WebApi.retrieveRecord("systemuser", Xrm.Utility.getGlobalContext().userSettings.userId.substring(1, 37), uri)
       .then(
            function (success) { //Anonymous function as callback
                if (success["_businessunitid_value@OData.Community.Display.V1.FormattedValue"] === "expected BU") {
                    if (namespace.formContext.ui.getFormType() === 1) {
                    }
                }
            },
            function (error) { //Anonymous function as callback
            }
       );
3. If you get error - "TypeError: Object doesn't support property or method 'includes'   at" when you have multi select picklist and the script checks for a selected value in the array using '.includes' then it is not compatible with ES5. Only ES6 supports '.includes', we have to use ES5 compatible 'indexOf'
	    //ES6 standard
	    if (formContext.getAttribute("new_multiselectfield").getValue().includes(2)) {
                //do something
            }
Remediated code is following: 
	    //ES5 standard
	    if (formContext.getAttribute("new_multiselectfield").getValue().indexOf(2) > -1) {
                //do something
            }

This was originally posted here.

Comments

*This post is locked for comments