2

有时(实际上大多数时候)当我尝试设置查找字段值时,该值已设置且可读,但该字段本身在表单上看起来是空白的。为什么会这样?传递的所有参数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);
  }
4

1 回答 1

3

在设置值之前尝试添加下一行

Xrm.Page.getAttribute("sgc_hr_case_initialcontact").setSubmitMode("always");
于 2012-10-10T13:35:55.957 回答