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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript setValue.

(0) ShareShare
ReportReport
Posted on by 189

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
    189 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans