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 に答える