Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer Service forum

addOnKeyPress event not working in Microsoft Dynamics 365 Version 1612 (8.2.2.112) (DB 8.2.2.112) on-premises

(0) ShareShare
ReportReport
Posted on by 75
Hi All,
function year_AutoComplete() {
debugger;
var results=null ;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/subjects?$select=subjectid,title&$count=true", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.send();

//req.onreadystatechange = function() {
if (req.readyState === 4) {
req.onreadystatechange = null;
if (req.status === 200) {
results = JSON.parse(req.response);
var recordCount = results["@odata.count"];

} else {
Xrm.Utility.alertDialog(req.statusText);
}
}

try {
resultSet = {
Subjectresults: new Array()
};
for (i = 0; i < results.value.length; i++) {
resultSet.Subjectresults.push({
id:results.value[i]["subjectid"],
fields: results.value[i]["title"]
});
}

if (resultSet.Subjectresults.length > 0) {
ext.getEventSource().showAutoComplete(resultSet);
} else {
ext.getEventSource().hideAutoComplete();
}
} catch (e) {
//console.log(e);
Xrm.Utility.alertDialog('Could not load Subjects: ' + e.message, null);
}

}

function Onload()
{
debugger;
Xrm.Page.getControl("rta_customsubject").addOnKeyPress(year_AutoComplete);
}

Could you please help me to resolve this problem. or suggest any other way to populate data in textbox.
Thanks.!
Categories:
  • Suggested answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,615 on at
    RE: addOnKeyPress event not working in Microsoft Dynamics 365 Version 1612 (8.2.2.112) (DB 8.2.2.112) on-premises

    2 tricky parts.

    One: did you debug & see the code works or breaks?

    Two: can subject entity be queried & filled in by auto-complete?

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: addOnKeyPress event not working in Microsoft Dynamics 365 Version 1612 (8.2.2.112) (DB 8.2.2.112) on-premises

    Hi Muhammad,

    I suspect its the web api request which is not returning the data and hence not shwing it in the auto complete. I would suggest to verify the auto complete feature with some hardcode values. Once it is working fine, change the source to pull it from web api.

    Refer this link for detailed - www.powerobjects.com/.../double-down-with-crm-2016-introducing-two-new-features-web-api-and-autocomplete

    Hope this helps.

  • Suggested answer
    Ben Thompson Profile Picture
    Ben Thompson 6,350 on at
    RE: addOnKeyPress event not working in Microsoft Dynamics 365 Version 1612 (8.2.2.112) (DB 8.2.2.112) on-premises

    The addOnKeyPress function only works on text fields see community.dynamics.com/.../185831 . community.dynamics.com/.../option-set-lookup-or-autocomplete has a good overview of the various options you could use...

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans