我需要帮助在动态365的主题树中添加一个新项目,使用Xrm和javascript。
答案 0 :(得分:0)
Subject与任何其他entity一样,您可以使用web api来创建它。
function createSubject() {
var serverURL = Xrm.Page.context.getClientUrl();
var subject = {};
subject["title"] = "test subject";
subject["featuremask"] = 1;
//subject["parentsubject@odata.bind"]="/subjects(<GUID without Quotes>)"; //setting existing lookup
subject["parentsubject"] = {
"title": "test parent subject",
"description": "deep insert to add parent before child",
"featuremask": 1
};
var req = new XMLHttpRequest();
req.open("POST", serverURL + "/api/data/v8.2/subjects", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function() {
if (this.readyState == 4 /* complete */ ) {
req.onreadystatechange = null;
if (this.status == 204) {
var subjectUri = this.getResponseHeader("OData-EntityId");
} else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send(JSON.stringify(subject));
}