web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript setValue.

(0) ShareShare
ReportReport
Posted on by 193

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

I have the same question (0)
  • Verified answer
    JFulfordMS Profile Picture
    193 on at

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

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Thanks for updating the Thread!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans