有时(实际上大多数情况下)当我尝试设置查找字段值时,该值已设置并可读,但字段本身在表单上看起来是空白的。
为什么会这样?传递给setSimpleLookupValue
的所有参数看起来都是正确的。
关于为什么会发生这种情况的任何想法?
这是完成大部分工作的功能:
function sgc_hr_getManager() {
var testContactId = Xrm.Page.getAttribute("sgc_hr_case_initialcontact").getValue();
if (testContactId != null) {
// do nothing - the field already has a value
} else {
var employeeVal = Xrm.Page.getAttribute("customerid").getValue();
if( employeeVal != null && employeeVal[0] && employeeVal[0].id != null ) {
var employeeId = Xrm.Page.getAttribute("customerid").getValue()[0].id;
employeeId = employeeId.replace('{','').replace('}','');
SDK.REST.retrieveRecord( employeeId, 'Contact', null, null, function( employee ) {
var managerId = employee.sgc_hr_ManagerId.Id;
if( managerId != null ) {
SDK.REST.retrieveRecord( managerId, 'Contact', null, null, function( manager ) {
// the following function call correctly sets the value
// but the control display is usually left blank
setSimpleLookupValue( 'sgc_hr_case_initialcontact', 'Contact', manager.ContactId, manager.FullName );
}, function(a) {
alert('An error occured! Unable to retrieve postholder record ' + managerId );
});
}
}, function(a) {
alert('An error occured! Unable to retrieve postholder record ' + employeeId );
})
} else {
alert('Cannot get employee details');
}
}
}
setSimpleLookupValue函数是标准函数,如下所示:
function setSimpleLookupValue(LookupId, Type, Id, Name) {
var lookupReference = [];
lookupReference[0] = {};
lookupReference[0].id = Id;
lookupReference[0].entityType = Type;
lookupReference[0].name = Name;
Xrm.Page.getAttribute(LookupId).setValue(lookupReference);
}
答案 0 :(得分:3)
在设置值
之前尝试添加下一行Xrm.Page.getAttribute("sgc_hr_case_initialcontact").setSubmitMode("always");