Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

JavaScript setValue.

Posted on by 185

This code isn't updating the field on the page. I've confirmed the correct values are present in the result object. Anyone able to help?

function onStateLookupFieldChanged() {
var stateId = Xrm.Page.getAttribute('tdn_usstateid').getValue()[0].id;
stateId = stateId.replace('{', '').replace('}', '');
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/tdn_usstates(" + stateId + ")?$select=tdn_statename", true);
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=\"*\"");
var result = null;
req.onreadystatechange = function (result) {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
result = JSON.parse(this.response);
Xrm.Page.getAttribute("address1_stateorprovince").setValue(result["tdn_statename"]);
} else {
alert(this.statusText);
}
}
};
req.send();
}

*This post is locked for comments

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: JavaScript setValue.

    Thanks for updating the Thread!

  • Verified answer
    JFulfordMS Profile Picture
    JFulfordMS 185 on at
    RE: JavaScript setValue.

    Found the issue. I was tabbing into the field that was trying to be set and preventing the javascript update. Wups.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans