2014-12-24 3 views
1

두 유형의 속성 인 LeaveType이 있습니다. 1. 유형, 2. 사용 가능 일, 여기서 유형은 옵션 세트이며 사용 가능한 날짜는 텍스트 필드입니다. 옵션 세트에서 Type = 'Annual'이 선택된 모든 LeaveType 레코드를 가져 오려고합니다. 옵션 집합 값에 대한 쿼리 식 필터를 추가하는 방법을 찾을 수 없습니다. 다음은 진행 방법입니다.MS CRM Query Expression에 필터 세트 옵션을 추가하는 방법은 무엇입니까?

public Entity Getleavetype(Guid LeaveDetailsId, IOrganizationService _orgService, CodeActivityContext Acontext) 
     { 
      QueryExpression GetLeavedetails = new QueryExpression(); 
      GetLeavedetails.EntityName = "sgfdhr_leavetype"; 
      GetLeavedetails.ColumnSet = new ColumnSet("new_type"); 
      GetLeavedetails.ColumnSet = new ColumnSet("new_availabledays"); 
      GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal, "Annual"); //Is this correct???? 
      GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, LeaveDetailsId); //ignore this 

      //((OptionSetValue)LeaveDetailsId["new_leavetype"]).Value 

      EntityCollection LeaveDetails = _orgService.RetrieveMultiple(GetLeavedetails); 
      return LeaveDetails[0]; 
     } 

답변

5

조건에 따라 레이블이 아닌 옵션 집합의 정수 값을 설정해야합니다. Annual 값이 예를 2라고 가정

, 코드는 다음과 같습니다 당신은 OptionSet 텍스트의 int 값을 찾기 위해 RetrieveAttributeRequest를 사용해야합니다

GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal, 2); 
+0

감사합니다. 이 코드를 도와 주시겠습니까 string value = ((OptionSetValue)LeaveDetails["new_leavetype"]).Value.toString(); // 정수 값이 아닌 옵션 집합의 문자열 값을 가져와야합니다. – geekstudent

+0

메타 데이터를 쿼리하는 데 필요한 레이블은 http://nishantrana.me/2010/12/24/get-value-for-optionset-in-crm-2011/에서 확인할 수 있습니다. –

0

.

private static int findParkedOptionValue(IOrganizationService service) 
{ 
    RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest 
    { 
     EntityLogicalName = Model.Invite.ENTITY_NAME, 
     LogicalName = Model.Invite.COLUMN_STATUS, 
     RetrieveAsIfPublished = false 
    }; 

    // Execute the request 
    RetrieveAttributeResponse attributeResponse = 
     (RetrieveAttributeResponse)service.Execute(attributeRequest); 
    var attributeMetadata = (EnumAttributeMetadata)attributeResponse.AttributeMetadata; 

    // Get the current options list for the retrieved attribute. 
    var optionList = (from o in attributeMetadata.OptionSet.Options 
         select new { Value = o.Value, Text = o.Label.UserLocalizedLabel.Label }).ToList(); 
    int value = (int)optionList.Where(o => o.Text == "Парковка") 
           .Select(o => o.Value) 
           .FirstOrDefault(); 
    return value; 

} 

https://community.dynamics.com/enterprise/b/crmmemories/archive/2017/04/20/retrieve-option-set-metadata-in-c에서 당신은 완벽한 예를 발견처럼 내 코드에서

가 보인다.

관련 문제