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)

Failed to load resource: the server responded with a status of 400 ()

(0) ShareShare
ReportReport
Posted on by 155

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

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    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

  • Viswanath Profile Picture
    93 on at

    hello Uma,

    how this issue got fixed for you? even i'm facing the same issue. 

    Regards, 

    Viswa

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