Object doesn't support property or method '

2019-09-10 02:05发布

I am using same code snippet as in this walk-through for adding addOnKeyPress event to name field of account form. But its pops out Object doesn't support property or method 'addOnKeyPress'as error but nothing get done.

I tried but nothing get done. I would like to hear from experts.

Update: Adding Code

function suggestAccounts() {

    // List of sample account names to suggest
    accounts = [
  { name: 'Blue Yonder Airlines', code: 'A06' },
  { name: 'City Power & Light', code: 'A07' },
  { name: 'Coho Vineyard', code: 'A08' },
  { name: 'Coho Winery', code: 'A09' },
  { name: 'Coho Vineyard & Winery', code: 'A10' },
  { name: 'Contoso, Ltd.', code: 'A11' },
  { name: 'Contoso Pharmaceuticals', code: 'A12' },
  { name: 'Contoso Suites', code: 'A13' },
  { name: 'Consolidated Messenger', code: 'A14' },
  { name: '​Fabrikam, Inc.', code: 'A15' },
  { name: 'Fabrikam Residences', code: 'A16' },
  { name: '​First Up Consultants', code: 'A17' },
  { name: 'Fourth Coffee', code: 'A18' },
  { name: 'Relecloud', code: 'A31' },
  { name: 'School of Fine Art', code: 'A32' },
  { name: 'Southridge Video', code: 'A33' },
  { name: 'Tailspin Toys', code: 'A34' },
  { name: 'Trey Research', code: 'A35' },
  { name: 'The Phone Company', code: 'A36' },
  { name: 'VanArsdel, Ltd.', code: 'A37' },
  { name: 'Wide World Importers', code: 'A38' },
  { name: '​Wingtip Toys', code: 'A39' },
  { name: 'Woodgrove Bank', code: 'A40' }    
    ];

    var keyPressFcn = function (ext) {
        try {
            var userInput = Xrm.Page.getControl("name").getValue();
            resultSet = {
                results: new Array(),
                commands: {
                    id: "sp_commands",
                    label: "Learn More",
                    action: function () {
                        // Specify what you want to do when the user
                        // clicks the "Learn More" link at the bottom
                        // of the auto-completion list.
                        // For this sample, we are just opening a page
                        // that provides information on working with
                        // accounts in CRM.
                        window.open("http://www.microsoft.com/en-us/dynamics/crm-customer-center/create-or-edit-an-account.aspx");
                    }
                }
            };

            var userInputLowerCase = userInput.toLowerCase();
            for (i = 0; i < accounts.length; i++) {
                if (userInputLowerCase === accounts[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {
                    resultSet.results.push({
                        id: i,
                        fields: [accounts[i].name]
                    });
                }
                if (resultSet.results.length >= 10) break;
            }

            if (resultSet.results.length > 0) {
                ext.getEventSource().showAutoComplete(resultSet);
            } else {
                ext.getEventSource().hideAutoComplete();
            }
        } catch (e) {
            // Handle any exceptions. In the sample code,
            // we are just displaying the exception, if any.
            console.log(e);
        }
    };

    Xrm.Page.getControl("name").addOnKeyPress(keyPressFcn);    
}

0条回答
登录 后发表回答