вот еще один пример:
Цитата:
function GetInfo() {
//Getting the Lookup object from the CRM Page
var ProjectObject = Xrm.Page.getAttribute("new_bonus_malusid").getValue();
// Getting the GUID for the Project record
var ProjectNoID= ProjectObject[0].id;
//Stripping out the curly brackets
ProjectNoID = ProjectNoID.replace('{', '').replace('}', '');
//Checking if we have a project GUID Value
if (ProjectNoID != null) {
//Let’s create the Web Service URL
oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
//Call the project retrieve function
RetrieveProjectRecord(ProjectNoID, oDataPath);
}
}
function RetrieveProjectRecord(Id, ODataPath) {
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", ODataPath + "/new_bonus_malusSet(guid'" + Id + "')", true);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () {
retrieveProjectReqCallBack(this);
};
retrieveReq.send();
}
function retrieveProjectReqCallBack(retrieveProjectReq) {
if (retrieveProjectReq.status == 200) {
var retrievedProject = this.parent.JSON.parse(retrieveProjectReq.responseText).d;
var ProjectName = retrievedProject.new_test;
Xrm.Page.getAttribute("new_testfield").setValue(ProjectName);
} else {
alert("Error in Fetching data");
}
}