Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Auto-Complete for Quick Create forms in 2016/365

(0) ShareShare
ReportReport
Posted on by

I've noticed that auto-complete (see: https://msdn.microsoft.com/en-us/library/mt607648.aspx) works fine in full forms but generates errors in Quick Create forms.  

Error: TypeError: Cannot read property 'addOnKeyPress' of null

I think it's due to non-existent fields.  I've tried to add them to the form and hide them with no luck.  Quick Create form types used to = 5 but that's been deprecated so I can't figure out how to conditionally execute based on form type.

Has anyone else run into this?

Thank you.

*This post is locked for comments

  • Suggested answer
    Oztrea Profile Picture
    Oztrea 45 on at
    RE: Auto-Complete for Quick Create forms in 2016/365

    You need to add a lookup on your quick create form, the library used for the auto complete is only loaded when a lookup is on the form. This lookup can be hidden (for example I'm adding Owner and uncheck visible by default) and magic… the autocomplete works again

  • RE: Auto-Complete for Quick Create forms in 2016/365

    Negative - i did not find a way.  We are also using on-prem (and I refuse to ever give MS control of my data).  Agreed that the documentation should make this stuff clearer.  Re. duplicating JS for full/QC forms, we just dealt with that issue yesterday.  While I've used CRM since 2005, I still consider myself green because I'm not a coder, and MS keeps making major changes to the architecture every other version which causes all of us to re-create a LOT of what we've worked so hard to build.  Very frustrating.  That all said, I can share what I *think* i know - I build a single version of the JS and then will make function calls as needed based on the form type, since I can control that (ie: the JS is tied to the specific form types).  I've also had to 'display' some undesired fields on my QC forms to make certain code work, and then I hide the fields so that the QC form is still a *quick* create form.  I don't know what MS was smoking when they deprecated the form type=5 since that would have been a much easier way to deal with things.  Sorry I can't be more help.

  • RE: Auto-Complete for Quick Create forms in 2016/365

    Daniel, did you ever find out how to distinguish between main forms and quick create forms? As you stated, Form Type = 5 was deprecated for quick create forms and now their Form Type = 1 just like the main form. I've tried using Xrm.Page.ui.formSelector.getCurrentItem(); but getCurrentItem() does not work on quick create forms either.

    Just for the record, I am very green in the world of CRM. We are currently using CRM 2016 On Prem.

    What I find frustrating is that the documentation does not specifically say that these methods will not work for quick create - it simply states that these methods are "...not available for Dynamics 365 mobile clients (phones and tablets) and the interactive service hub." I am assuming that the reason that the methods are not available for mobile clients is because the mobile app uses quick create forms. It seems like there should be a way to know if the user is using the quick create verses the main form... otherwise I will have to duplicate my javascript resource files for every quick create form I create to find another way to accomplish the desired functionality being enabled with these methods. Obviously this is less than desirable. Surely I am missing something.

     

  • RE: Auto-Complete for Quick Create forms in 2016/365

    Hello Pankaj,

    address_composite is not a classic type in CRM, it encapsulates a mini form in order to enter the address fields. I don't think you will be able to set completion for this type of field.

    Regards,

    Emmanuel Barache

  • RE: Auto-Complete for Quick Create forms in 2016/365

    Hi Guys,

    I wish to add Autocomplete  on  Sales-> Account-> Contact section in CRM 365 .

    In Contact section there are Address Filed[ this is "address1_composite"] , which contain country,State,Pincode and many more. 

    I wish to  autocomplete  on Key press of country.

    ex:-  Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_country_i").addOnKeyPress(KeyPressDataLoad);

    I am trying but getting error "Cannot read property 'addOnKeyPress' of null".

    Please help me out.

    Thanks

    Pankaj vats

  • RE: Auto-Complete for Quick Create forms in 2016/365

    Thank you Nithya.

    I wish that (stackoverflow.com/.../crm-2016-autocomplete - "You must have a lookup control on the form in order for the autocomplete to render.") were the solution but it's not. I do have a lookup on the form and still have the problem. Only way I've found to solve the problem is to not use auto-complete on quick forms.

    Code and errors below for reference if anyone has ideas.  Code works as expected on full forms.

    TypeError: Cannot read property 'addOnKeyPress' of null
    at suggestStates (https://crm.***/%7B636203259450000749%7D/WebResources/new_Address_Phone_main_libraryjs?ver=1238576589:238:52)
    at eval (eval at RunHandlerInternal (https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:153:1), <anonymous>:1:1)
    at RunHandlerInternal (https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:158:1)
    at RunHandlers (https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:117:1)
    at OnScriptTagLoaded (https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:232:1)
    at https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:201:1

    1_2D00_18_2D00_2017-1_2D00_36_2D00_03-PM.jpg

    1_2D00_18_2D00_2017-1_2D00_36_2D00_03-PM.jpg

    function suggestStates() {

        // List of states to suggest

        // Good explanation: blog.singular.co.za/.../auto-completion-for-text-controls-on-crm-2016-forms

        States = [

    { name: 'AL', spell: 'Alabama', code: 'S01' },

    { name: 'AK', spell: 'Alaska', code: 'S02' },

    { name: 'AZ', spell: 'Arizona', code: 'S03' },

    { name: 'AR', spell: 'Arkansas', code: 'S04' },

    { name: 'CA', spell: 'California', code: 'S05' },

    { name: 'CO', spell: 'Colorado', code: 'S06' },

    { name: 'CT', spell: 'Connecticut', code: 'S07' },

    { name: 'DE', spell: 'Delaware', code: 'S08' },

    { name: 'FL', spell: 'Florida', code: 'S09' },

    { name: 'GA', spell: 'Georgia', code: 'S10' },

    { name: 'HI', spell: 'Hawaii', code: 'S11' },

    { name: 'ID', spell: 'Idaho', code: 'S12' },

    { name: 'IL', spell: 'Illinois', code: 'S13' },

    { name: 'IN', spell: 'Indiana', code: 'S14' },

    { name: 'IA', spell: 'Iowa', code: 'S15' },

    { name: 'KS', spell: 'Kansas', code: 'S16' },

    { name: 'KY', spell: 'Kentucky', code: 'S17' },

    { name: 'LA', spell: 'Louisiana', code: 'S18' },

    { name: 'ME', spell: 'Maine', code: 'S19' },

    { name: 'MD', spell: 'Maryland', code: 'S20' },

    { name: 'MA', spell: 'Massachusetts', code: 'S21' },

    { name: 'MI', spell: 'Michigan', code: 'S22' },

    { name: 'MN', spell: 'Minnesota', code: 'S23' },

    { name: 'MS', spell: 'Mississippi', code: 'S24' },

    { name: 'MO', spell: 'Missouri', code: 'S25' },

    { name: 'MT', spell: 'Montana', code: 'S26' },

    { name: 'NE', spell: 'Nebraska', code: 'S27' },

    { name: 'NV', spell: 'Nevada', code: 'S28' },

    { name: 'NH', spell: 'New Ampshire', code: 'S29' },

    { name: 'NJ', spell: 'New Jersey', code: 'S30' },

    { name: 'NM', spell: 'New Mexico', code: 'S31' },

    { name: 'NY', spell: 'New York', code: 'S32' },

    { name: 'NC', spell: 'North Carolina', code: 'S33' },

    { name: 'ND', spell: 'North Dakota', code: 'S34' },

    { name: 'OH', spell: 'Ohio', code: 'S35' },

    { name: 'OK', spell: 'Oklahoma', code: 'S36' },

    { name: 'OR', spell: 'Oregon', code: 'S37' },

    { name: 'PA', spell: 'Pennsylvania', code: 'S38' },

    { name: 'RI', spell: 'Rhode Island', code: 'S39' },

    { name: 'SC', spell: 'South Carolina', code: 'S40' },

    { name: 'SD', spell: 'South Dakota', code: 'S41' },

    { name: 'TN', spell: 'Tennessee', code: 'S42' },

    { name: 'TX', spell: 'Texas', code: 'S43' },

    { name: 'UT', spell: 'Utah', code: 'S44' },

    { name: 'VT', spell: 'Vermont', code: 'S45' },

    { name: 'VA', spell: 'Virginia', code: 'S46' },

    { name: 'WA', spell: 'Washington', code: 'S47' },

    { name: 'WV', spell: 'West Virginia', code: 'S48' },

    { name: 'WI', spell: 'Wisconsin', code: 'S49' },

    { name: 'WY', spell: 'Wyoming', code: 'S50' }

        ];

        var keyPressFcn = function (ext) {

            // Get value typed by user

            try {

                var userInput = Xrm.Page.getControl("address1_stateorprovince").getValue();

                // Define an empty resultset that will be used as the source for the autocomplete box.

                resultSet = {

                    results: new Array(),

                    commands: {

                        id: "sp_commands",

                        // This will put an icon bottom right of window

                        //icon: "../WebResources/new_City_16.png",

                        //This will add the Link at the bottom of the auto complete search result

                        label: "",

                        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("www.microsoft.com/.../create-or-edit-an-account.aspx");

                        }

                    }

                };

                // In this example, we will cycle through the array of possible values looking for a match.

                var userInputLowerCase = userInput.toLowerCase();

                for (i = 0; i < States.length; i++) {

                    // Check if the entry in the array matches the typed characters. 

                    // If so, add the matching values to the resultset that will be displayed in the autocomplete box.

                    if (userInputLowerCase === States[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {

                        resultSet.results.push({

                            id: i,

                            fields: [States[i].name, States[i].spell]

                        });

                    }

                    // Limit the autocomplete list to 10 entries

                    if (resultSet.results.length >= 10) break;

                }

                // Display the autocomplete box if there were matching entries found. Otherwise, hide it.

                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);

            }

        };

        var keyPressFcn2 = function (ext) {

            try {

                var userInput = Xrm.Page.getControl("address2_stateorprovince").getValue();

                resultSet = {

                    results: new Array(),

                    commands: {

                        id: "sp_commands",

                        label: "",

                        action: function () {}

                    }

                };

              var userInputLowerCase = userInput.toLowerCase();

                for (i = 0; i < States.length; i++) {

                    if (userInputLowerCase === States[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {

                        resultSet.results.push({

                            id: i,

                            fields: [States[i].name, States[i].spell]

                        });

                    }

                    if (resultSet.results.length >= 10) break;

                }

                if (resultSet.results.length > 0) {

                    ext.getEventSource().showAutoComplete(resultSet);

                } else {

                    ext.getEventSource().hideAutoComplete();

                }

            } catch (e) {

                console.log(e);

            }

        };

        var keyPressFcn3 = function (ext) {

            try {

                var userInput = Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_stateorprovince").getValue();

                resultSet = {

                    results: new Array(),

                    commands: {

                        id: "sp_commands",

                        label: "",

                        action: function () { }

                    }

                };

                var userInputLowerCase = userInput.toLowerCase();

                for (i = 0; i < States.length; i++) {

                    if (userInputLowerCase === States[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {

                        resultSet.results.push({

                            id: i,

                            fields: [States[i].name, States[i].spell]

                        });

                    }

                    if (resultSet.results.length >= 10) break;

                }

                if (resultSet.results.length > 0) {

                    ext.getEventSource().showAutoComplete(resultSet);

                } else {

                    ext.getEventSource().hideAutoComplete();

                }

            } catch (e) {

                console.log(e);

            }

        };

        Xrm.Page.getControl("address1_stateorprovince").addOnKeyPress(keyPressFcn);

        Xrm.Page.getControl("address2_stateorprovince").addOnKeyPress(keyPressFcn2);

        Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_stateorprovince").addOnKeyPress(keyPressFcn3);

    }

  • RE: Auto-Complete for Quick Create forms in 2016/365

    I think you can add js library on Quick Create Form.

    I was able to successfully add autocomplete on name field of opportunity quick form.

    Refer this:

    https://msdn.microsoft.com/en-in/library/mt607648.aspx

    6378.Capture.PNG

    autocomplete only works for text fields.

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Auto-Complete for Quick Create forms in 2016/365

    Hi Daniel,

    Please refer the following thread. It describes the same issue you are discussing about.

    stackoverflow.com/.../crm-2016-autocomplete

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,401 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans