Hi together,
a wrote a script calling the autocomplete function for the different forms (contact, account, lead). This is a list with postalcodes (plz), cities and provinces (Bundesland in German).
The function "companyname_postalcodelistfunc()" is placed in the onload-trigger, the function "companyname_setvaluesofpostcodelist()" in the onchange trigger of the postalcode field. (There's a check function on the onsave as well, but this doesn't matter right now, because there are no problems)
It works fine. But... if there's a postalcode (plz) that stands for more than one city the last city is set in the city field (so to say the last of the shown array).
(Of course the list is much longer, but I shortened it for this posting)
So e.g. when I chose "plz: '53539', name: 'Borler', bundesland: 'Rheinland-Pfalz'", the value which is set is "plz: '53539', name: 'Welcherath', bundesland: 'Rheinland-Pfalz'"
What do I have to do to get the chosen value to be set in the fields?
Best regards
Mick
var companyname_postalcodeslist = [ { plz: '01454', name: 'Wachau', bundesland: 'Sachsen' }, { plz: '01458', name: 'Ottendorf-Okrilla', bundesland: 'Sachsen' }, { plz: '01465', name: 'Dresden', bundesland: 'Sachsen' }, { plz: '53534', name: 'Wirft', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Bodenbach', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Bongard', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Borler', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Brücktal', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Gelenberg', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Kelberg', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Kirsbach', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Reimerath', bundesland: 'Rheinland-Pfalz' }, { plz: '53539', name: 'Welcherath', bundesland: 'Rheinland-Pfalz' } ]; function companyname_postalcodelistfunc() { var resultPLZ = function (ext) { try { var userInput = Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_postalcode").getValue(); resultSet = { results: new Array() }; var userInputLowerCase = userInput; for (i = 0; i < companyname_postalcodeslist.length; i++) { if (userInputLowerCase === companyname_postalcodeslist[i].plz.substring(0, userInputLowerCase.length)) { resultSet.results.push({ id: i, fields: [companyname_postalcodeslist[i].plz, companyname_postalcodeslist[i].ide, companyname_postalcodeslist[i].name], name: companyname_postalcodeslist[i].name }); } // alert("1" + companyname_postalcodeslist[i].ide); 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_composite_compositionLinkControl_address1_postalcode").addOnKeyPress(resultPLZ); Xrm.Page.getControl("jobtitle").addOnKeyPress(resultPLZ); } function companyname_setvaluesofpostcodelist() { var companyname_postalCodevalue = Xrm.Page.getAttribute("address1_postalcode").getValue(); for (var i = 0; i < companyname_postalcodeslist.length; i++) { if (companyname_postalCodevalue === companyname_postalcodeslist[i].plz) { var germany = "Deutschland"; var cityfieldvalue = companyname_postalcodeslist[i].name; var provincefieldvalue = companyname_postalcodeslist[i].bundesland; Xrm.Page.getAttribute("address1_city").setValue(cityfieldvalue); Xrm.Page.getAttribute("address1_stateorprovince").setValue(provincefieldvalue); Xrm.Page.getAttribute("address1_country").setValue(germany); } } }
*This post is locked for comments
Hi Ravi,
it works fine now. Thank you!
Best regards
Mick
Hi Ravi,
That's a nice idea.
I'm gonna try it after my holidays and give a feedback directly.
Best regards and many thanks
Mick
Hi Mick,
If I am not wrong, the only option is to concatenate the id to your plz i.e. plz + "[" + id + "]" and set this in the resultset such that in the results it will appears as 553539 [1], 553539 [2], 553539 [3]...
And then when you get the selected values in method companyname_setvaluesofpostcodelist, instead of searching the plz, serch it based on the id.
Hope this helps.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156