[Dynamics CRM] 上如何用程式關閉自訂實體紀錄

  • 2348
  • 0
  • 2011-10-14

當CRM需停用記錄時,需要設定 state code 和 status code。

FW : Status Codes when Deactivating Records in CRM 4.0

當CRM需停用記錄時,需要設定 state code 和 status code。

下面是程式碼停用自定實體紀錄。對於系統的實體,以每個實體為特定對象, 例: SetStateOpportunityRequest.

   1:              SetStateDynamicEntityRequest deactivate = new SetStateDynamicEntityRequest();
   2:              deactivate.Entity = new Moniker("new_job", id);
   3:              deactivate.State = "Inactive";
   4:              deactivate.Status = 2;
   5:              SetStateDynamicEntityResponse resp = (SetStateDynamicEntityResponse)service.Execute(deactivate);

 

 

 

 

 

為了取得 state code 和 status code , 請打開 StatusCode 屬性和下拉選單來檢視 state code 和 status code。

另一種方法是從 SQL 查看狀態代碼。它在同一個地方顯示所有的可能性組合。

StateCode/Status Code SQL查詢

   1:  select Entity.Name,
   2:  stringmapstatuscode.value as statusstring,
   3:   stringmapstatecode.value as statestring,
   4:   statusmap.status
   5:  from StatusMap
   6:  JOIN stringmap stringmapstatuscode on StatusMap.status = stringmapstatuscode.AttributeValue
   7:  and stringmapstatuscode.ObjectTypeCode = StatusMap.ObjectTypeCode
   8:  and stringmapstatuscode.attributename = 'statuscode'
   9:  JOIN stringmap stringmapstatecode on StatusMap.state = stringmapstatecode.AttributeValue
  10:  and stringmapstatecode.ObjectTypeCode = StatusMap.ObjectTypeCode
  11:  and stringmapstatecode.attributename = 'statecode'
  12:  JOIN Entity on Entity.ObjectTypeCode = stringmapstatuscode.ObjectTypeCode
  13:  where
  14:  Entity.Name = 'new_job'
  15:  order by StatusMap.state, statusmap.status