当我尝试设置查找值时,首先保存然后设置查找并刷新表单。因此,它删除了查找字段。我该如何解决?
主要功能
Xrm.Page.getAttribute("new_personsendsapproval").setSubmitMode("always");
setInfo("new_personsendsapproval");
Xrm.Page.getAttribute("statuscode").setSubmitMode("always");
Xrm.Page.getAttribute("statuscode").setValue(100000000);
Xrm.Page.data.entity.save();
setInfo()函数
function setInfo(fieldname) {
var context;
var serverUrl;
var UserID;
var ODataPath;
context = Xrm.Page.context;
serverUrl = context.getServerUrl();
UserID = context.getUserId();
ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var retrieveUserReq = new XMLHttpRequest();
retrieveUserReq.open("GET", ODataPath + "/SystemUserSet(guid'" + UserID + "')", true);
retrieveUserReq.setRequestHeader("Accept", "application/json");
retrieveUserReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveUserReq.onreadystatechange = function () {
retrieveUserReqCallBack(this, fieldname);
};
retrieveUserReq.send();
}
回调功能
function retrieveUserReqCallBack(retrieveUserReq, fieldname) {
if (retrieveUserReq.readyState == 4 /* complete */) {
if (retrieveUserReq.status == 200) {
var retrievedUser = this.parent.JSON.parse(retrieveUserReq.responseText).d;
if (retrievedUser.FullName != null)
debugger;
var setUservalue = new Array();
setUservalue[0] = new Object();
setUservalue[0].id = Xrm.Page.context.getUserId();
setUservalue[0].entityType = 'systemuser';
setUservalue[0].name = retrievedUser.FullName;
Xrm.Page.getAttribute(fieldname).setSubmitMode("always");
Xrm.Page.getAttribute(fieldname).setValue(setUservalue);
}
else {
}
}
}
答案 0 :(得分:1)
您需要使呼叫同步,例如
retrieveUserReq.open("GET", ODataPath + "/SystemUserSet(guid'" + UserID + "')", false );