Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

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

  • Viswanath Profile Picture
    Viswanath 90 on at
    RE: Failed to load resource: the server responded with a status of 400 ()

    hello Uma,

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

    Regards, 

    Viswa

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Failed to load resource: the server responded with a status of 400 ()

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans