Skip to main content



No record found.

Microsoft Dynamics CRM forum

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();"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);
} else {

  • RaviKashyap Profile Picture
    RaviKashyap 55,406 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans