Dear Experts,
I'm Having Building Entity in that i have Project Lookup and Project Location Look up, In Project Entity again i'm having Project Location Lookup.
Now i need to to set the Project location based on selected project value...
for that i have written Javascript
//===============================================//
//To set the state value on change of project
//==============================================//
function projectLocation() {
debugger;
try {
var project = null;
project = Xrm.Page.getAttribute("alk_projectcommunity").getValue();
if (project != null && project != undefined) {
var selectedProject = getLookup(project);
var projectid = selectedProject.id.replace(/\{|\}/gi, '');
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/alk_projectcommunities(" + projectid + ")$select=_alk_projectlocation_value", 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=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
// req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var stateId = result["_alk_projectlocation_value"];
var stateName = result["_alk_projectlocation_value@OData.Community.Display.V1.FormattedValue"];
setLookup(stateId, stateName, "alk_location", "alk_projectlocation");
Xrm.Page.getAttribute("alk_projectlocation").setSubmitMode("always");
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
else {
Xrm.Page.getAttribute("alk_projectlocation").setValue(null);
Xrm.Page.getAttribute("alk_projectlocation").setSubmitMode("always");
}
Xrm.Page.data.entity.save("save");
}
catch (e) {
alert("Error: " + e.description);
}
}
//Set a lookup value
function setLookup(recorid, field, entityname, leadfield) {
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = recorid;
lookup[0].name = field;
lookup[0].entityType = entityname;
Xrm.Page.getAttribute(leadfield).setValue(lookup);
}
//Get a lookup value
function getLookup(lookup) {
if (lookup != null) {
return {
name: lookup[0].name,
id: lookup[0].id,
entityType: lookup[0].entityType
};
}
else {
return {
name: "",
id: "",
entityType: ""
};
}
}
i'm getting Failed to load resource: the server responded with a status of 400 () error
can any one help me on this.
Note: I'm Using Dynamics 365 9.0 version.
Regards
Uma
*This post is locked for comments
hello Uma,
how this issue got fixed for you? even i'm facing the same issue.
Regards,
Viswa
Hello Uma,
- Make sure you are using correct schema name of the entity
- Try to debug your code and check if server url is forming correctly.
- You can look for sample code here as well: himbap.com/blog
I will suggest you to use Rest Build to first test your query, github.com/.../CRMRESTBuilder and you can use query using javascript
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156