전역 옵션 집합 사용자 지정
게시 날짜: 2016년 11월
적용 대상: Dynamics CRM 2015
다른 필드에서 한 위치에 유지되는 동일한 옵션 집합을 공유할 수 있도록 일반적으로 전역 옵션 집합을 사용하여 필드를 설정합니다. 전역 옵션 집합을 재사용할 수 있습니다. 열거형과 유사한 방식으로 요청 매개 변수에도 사용됩니다.
OptionMetadata를 사용하여 옵션 값을 정의할 경우 시스템에서 값을 할당할 수 있도록 하는 것이 좋습니다. 새 OptionMetadata 인스턴스를 만들 때 null 값을 전달하여 이를 수행합니다. 옵션을 정의할 때, 옵션 집합이 생성된 솔루션에 대한 게시자 설정의 컨텍스트에 특화된 옵션 값 접두사를 포함합니다. 관리된 솔루션이 설치된 조직에 정의된 모든 옵션 집합에서, 이 접두사는 관리된 솔루션에 대해 중복된 옵션 집합을 생성할 가능성을 줄여줍니다. 자세한 내용은 옵션 집합 옵션 병합을 참조하십시오.
이 항목의 내용
전역 옵션 집합 검색
전역 옵션 집합 만들기
전역 옵션 집합을 사용하는 선택 목록 만들기
전역 옵션 집합 업데이트
모든 전역 옵션 집합 검색
전역 옵션 집합 삭제
전역 옵션 집합 검색
다음 샘플은 RetrieveOptionSetRequest 메시지를 사용하여 이름별로 전역 옵션 집합을 검색하는 방법을 보여 줍니다.
// Use the RetrieveOptionSetRequest message to retrieve
// a global option set by it's name.
RetrieveOptionSetRequest retrieveOptionSetRequest =
new RetrieveOptionSetRequest
{
Name = _globalOptionSetName
};
// Execute the request.
RetrieveOptionSetResponse retrieveOptionSetResponse =
(RetrieveOptionSetResponse)_serviceProxy.Execute(
retrieveOptionSetRequest);
Console.WriteLine("Retrieved {0}.",
retrieveOptionSetRequest.Name);
// Access the retrieved OptionSetMetadata.
OptionSetMetadata retrievedOptionSetMetadata =
(OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;
// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
retrievedOptionSetMetadata.Options.ToArray();
' Use the RetrieveOptionSetRequest message to retrieve
' a global option set by it's name.
Dim retrieveOptionSetRequest As RetrieveOptionSetRequest = New RetrieveOptionSetRequest With {
.Name = _globalOptionSetName
}
' Execute the request.
Dim retrieveOptionSetResponse As RetrieveOptionSetResponse =
CType(_serviceProxy.Execute(retrieveOptionSetRequest), RetrieveOptionSetResponse)
Console.WriteLine("Retrieved {0}.", retrieveOptionSetRequest.Name)
' Access the retrieved OptionSetMetadata.
Dim retrievedOptionSetMetadata As OptionSetMetadata =
CType(retrieveOptionSetResponse.OptionSetMetadata, OptionSetMetadata)
' Get the current options list for the retrieved attribute.
Dim optionList() As OptionMetadata = retrievedOptionSetMetadata.Options.ToArray()
전역 옵션 집합 만들기
CreateOptionSetRequest 메시지를 사용하여 새 전역 옵션 집합을 만듭니다.IsGlobal 속성을 true로 설정하여 옵션 집합이 전역임을 나타냅니다. 다음 코드 예제에서는 “Example Option Set”이라는 전역 옵션 집합을 만듭니다.
#region How to create global option set
// Define the request object and pass to the service.
CreateOptionSetRequest createOptionSetRequest = new CreateOptionSetRequest
{
// Create a global option set (OptionSetMetadata).
OptionSet = new OptionSetMetadata
{
Name = _globalOptionSetName,
DisplayName = new Label("Example Option Set", _languageCode),
IsGlobal = true,
OptionSetType = OptionSetType.Picklist,
Options =
{
new OptionMetadata(new Label("Open", _languageCode), null),
new OptionMetadata(new Label("Suspended", _languageCode), null),
new OptionMetadata(new Label("Cancelled", _languageCode), null),
new OptionMetadata(new Label("Closed", _languageCode), null)
}
}
};
// Execute the request.
CreateOptionSetResponse optionsResp =
(CreateOptionSetResponse)_serviceProxy.Execute(createOptionSetRequest);
' #Region "How to create global option set"
' Define the request object and pass to the service.
Dim createOptionSetRequest As CreateOptionSetRequest = New CreateOptionSetRequest()
Dim createOptionSetOptionSet As OptionSetMetadata = New OptionSetMetadata() With {
.Name = _globalOptionSetName,
.DisplayName = New Label("Example Option Set", _languageCode),
.IsGlobal = True,
.OptionSetType = OptionSetType.Picklist
}
createOptionSetOptionSet.Options.AddRange(
{
New OptionMetadata(New Label("Open", _languageCode), Nothing),
New OptionMetadata(New Label("Suspended", _languageCode), Nothing),
New OptionMetadata(New Label("Cancelled", _languageCode), Nothing),
New OptionMetadata(New Label("Closed", _languageCode), Nothing)
}
)
createOptionSetRequest.OptionSet = createOptionSetOptionSet
' Create a global option set (OptionSetMetadata).
' Execute the request.
Dim optionsResp As CreateOptionSetResponse =
CType(_serviceProxy.Execute(createOptionSetRequest), CreateOptionSetResponse)
전역 옵션 집합을 사용하는 선택 목록 만들기
다음 샘플은 CreateAttributeRequest를 사용하여 전역 옵션 집합을 사용하는 선택 목록 특성을 만드는 방법을 보여 줍니다.
// Create a Picklist linked to the option set.
// Specify which entity will own the picklist, and create it.
CreateAttributeRequest createRequest = new CreateAttributeRequest
{
EntityName = Contact.EntityLogicalName,
Attribute = new PicklistAttributeMetadata
{
SchemaName = "sample_examplepicklist",
LogicalName = "sample_examplepicklist",
DisplayName = new Label("Example Picklist", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
// In order to relate the picklist to the global option set, be sure
// to specify the two attributes below appropriately.
// Failing to do so will lead to errors.
OptionSet = new OptionSetMetadata
{
IsGlobal = true,
Name = _globalOptionSetName
}
}
};
_serviceProxy.Execute(createRequest);
' Create a Picklist linked to the option set.
' Specify which entity will own the picklist, and create it.
Dim createRequest As CreateAttributeRequest = New CreateAttributeRequest With {
.EntityName = Contact.EntityLogicalName,
.Attribute = New PicklistAttributeMetadata With {
.SchemaName = "sample_examplepicklist", .LogicalName = "sample_examplepicklist",
.DisplayName = New Label("Example Picklist", _languageCode),
.RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
.OptionSet = New OptionSetMetadata With {
.IsGlobal = True,
.Name = _globalOptionSetName
}
}
}
' In order to relate the picklist to the global option set, be sure
' to specify the two attributes below appropriately.
' Failing to do so will lead to errors.
_serviceProxy.Execute(createRequest)
전역 옵션 집합 업데이트
다음 샘플은 UpdateOptionSetRequest를 사용하여 전역 옵션 집합의 레이블을 업데이트하는 방법을 보여 줍니다.
// Use UpdateOptionSetRequest to update the basic information of an option
// set. Updating option set values requires different messages (see below).
UpdateOptionSetRequest updateOptionSetRequest = new UpdateOptionSetRequest
{
OptionSet = new OptionSetMetadata
{
DisplayName = new Label("Updated Option Set", _languageCode),
Name = _globalOptionSetName,
IsGlobal = true
}
};
_serviceProxy.Execute(updateOptionSetRequest);
//Publish the OptionSet
PublishXmlRequest pxReq1 = new PublishXmlRequest { ParameterXml = String.Format("<importexportxml><optionsets><optionset>{0}</optionset></optionsets></importexportxml>", _globalOptionSetName) };
_serviceProxy.Execute(pxReq1);
' Use UpdateOptionSetRequest to update the basic information of an option
' set. Updating option set values requires different messages (see below).
Dim updateOptionSetRequest As UpdateOptionSetRequest = New UpdateOptionSetRequest With {
.OptionSet = New OptionSetMetadata With {
.DisplayName = New Label("Updated Option Set", _languageCode),
.Name = _globalOptionSetName,
.IsGlobal = True
}
}
_serviceProxy.Execute(updateOptionSetRequest)
'Publish the OptionSet
Dim pxReq1 As PublishXmlRequest = New PublishXmlRequest With {
.ParameterXml = String.Format("<importexportxml><optionsets><optionset>{0}</optionset></optionsets></importexportxml>", _globalOptionSetName)
}
_serviceProxy.Execute(pxReq1)
옵션 순서 설정
다음 샘플은 OrderOptionRequest를 사용하여 전역 옵션 집합에서 옵션을 정렬할 수 있는 방법을 보여 줍니다.
// Change the order of the original option's list.
// Use the OrderBy (OrderByDescending) linq function to sort options in
// ascending (descending) order according to label text.
// For ascending order use this:
var updateOptionList =
optionList.OrderBy(x => x.Label.LocalizedLabels[0].Label).ToList();
// For descending order use this:
// var updateOptionList =
// optionList.OrderByDescending(
// x => x.Label.LocalizedLabels[0].Label).ToList();
// Create the request.
OrderOptionRequest orderOptionRequest = new OrderOptionRequest
{
// Set the properties for the request.
OptionSetName = _globalOptionSetName,
// Set the changed order using Select linq function
// to get only values in an array from the changed option list.
Values = updateOptionList.Select(x => x.Value.Value).ToArray()
};
// Execute the request
_serviceProxy.Execute(orderOptionRequest);
//Publish the OptionSet
PublishXmlRequest pxReq4 = new PublishXmlRequest { ParameterXml = String.Format("<importexportxml><optionsets><optionset>{0}</optionset></optionsets></importexportxml>", _globalOptionSetName) };
_serviceProxy.Execute(pxReq4);
' Change the order of the original option's list.
' Use the OrderBy (OrderByDescending) linq function to sort options in
' ascending (descending) order according to label text.
' For ascending order use this:
Dim updateOptionList = optionList.OrderBy(Function(x) x.Label.LocalizedLabels(0).Label).ToList()
' For descending order use this:
' var updateOptionList =
' optionList.OrderByDescending(
' x => x.Label.LocalizedLabels[0].Label).ToList();
' Create the request.
Dim orderOptionRequest As OrderOptionRequest =
New OrderOptionRequest With {
.OptionSetName = _globalOptionSetName,
.Values = updateOptionList.Select(Function(x) x.Value.Value).ToArray()
}
' Set the properties for the request.
' Set the changed order using Select linq function
' to get only values in an array from the changed option list.
' Execute the request
_serviceProxy.Execute(orderOptionRequest)
'Publish the OptionSet
Dim pxReq4 As PublishXmlRequest =
New PublishXmlRequest With {
.ParameterXml = String.Format("<importexportxml><optionsets><optionset>{0}</optionset></optionsets></importexportxml>",
_globalOptionSetName)
}
_serviceProxy.Execute(pxReq4)
모든 전역 옵션 집합 검색
다음 샘플에서는 RetrieveAllOptionSetsRequest를 사용하여 모든 전역 옵션 집합을 검색하는 방법을 보여 줍니다.
// Use RetrieveAllOptionSetsRequest to retrieve all global option sets.
// Create the request.
RetrieveAllOptionSetsRequest retrieveAllOptionSetsRequest =
new RetrieveAllOptionSetsRequest();
// Execute the request
RetrieveAllOptionSetsResponse retrieveAllOptionSetsResponse =
(RetrieveAllOptionSetsResponse)_serviceProxy.Execute(
retrieveAllOptionSetsRequest);
// Now you can use RetrieveAllOptionSetsResponse.OptionSetMetadata property to
// work with all retrieved option sets.
if (retrieveAllOptionSetsResponse.OptionSetMetadata.Count() > 0)
{
Console.WriteLine("All the global option sets retrieved as below:");
int count = 1;
foreach (OptionSetMetadataBase optionSetMetadata in
retrieveAllOptionSetsResponse.OptionSetMetadata)
{
Console.WriteLine("{0} {1}", count++,
(optionSetMetadata.DisplayName.LocalizedLabels.Count >0)? optionSetMetadata.DisplayName.LocalizedLabels[0].Label : String.Empty);
}
}
' Use RetrieveAllOptionSetsRequest to retrieve all global option sets.
' Create the request.
Dim retrieveAllOptionSetsRequest As New RetrieveAllOptionSetsRequest()
' Execute the request
Dim retrieveAllOptionSetsResponse As RetrieveAllOptionSetsResponse =
CType(_serviceProxy.Execute(retrieveAllOptionSetsRequest), RetrieveAllOptionSetsResponse)
' Now you can use RetrieveAllOptionSetsResponse.OptionSetMetadata property to
' work with all retrieved option sets.
If retrieveAllOptionSetsResponse.OptionSetMetadata.Count() > 0 Then
Console.WriteLine("All the global option sets retrieved as below:")
Dim count As Integer = 1
For Each optionSetMetadata As OptionSetMetadataBase In retrieveAllOptionSetsResponse.OptionSetMetadata
Console.WriteLine("{0} {1}",
count,
If(optionSetMetadata.DisplayName.LocalizedLabels.Count > 0,
optionSetMetadata.DisplayName.LocalizedLabels(0).Label,
String.Empty))
count += 1
Next optionSetMetadata
End If
전역 옵션 집합 삭제
다음 샘플에서는 RetrieveDependentComponentsRequest를 사용하여 전역 옵션 집합이 다른 솔루션 구성 요소에서 사용 중인지 여부를 확인하는 방법과 DeleteOptionSetRequest를 사용하여 삭제하는 방법을 보여 줍니다.
// Create the request to see which components have a dependency on the
// global option set.
RetrieveDependentComponentsRequest dependencyRequest =
new RetrieveDependentComponentsRequest
{
ObjectId = _optionSetId,
ComponentType = (int)componenttype.OptionSet
};
RetrieveDependentComponentsResponse dependencyResponse =
(RetrieveDependentComponentsResponse)_serviceProxy.Execute(
dependencyRequest);
// Here you would check the dependencyResponse.EntityCollection property
// and act as appropriate. However, we know there is exactly one
// dependency so this example deals with it directly and deletes
// the previously created attribute.
DeleteAttributeRequest deleteAttributeRequest =
new DeleteAttributeRequest
{
EntityLogicalName = Contact.EntityLogicalName,
LogicalName = "sample_examplepicklist"
};
_serviceProxy.Execute(deleteAttributeRequest);
Console.WriteLine("Referring attribute deleted.");
#endregion How to delete attribute
#region How to delete global option set
// Finally, delete the global option set. Attempting this before deleting
// the picklist above will result in an exception being thrown.
DeleteOptionSetRequest deleteRequest = new DeleteOptionSetRequest
{
Name = _globalOptionSetName
};
_serviceProxy.Execute(deleteRequest);
' Create the request to see which components have a dependency on the
' global option set.
Dim dependencyRequest As RetrieveDependentComponentsRequest =
New RetrieveDependentComponentsRequest With {
.ObjectId = _optionSetId,
.ComponentType = componenttype.OptionSet
}
Dim dependencyResponse As RetrieveDependentComponentsResponse =
CType(_serviceProxy.Execute(dependencyRequest), RetrieveDependentComponentsResponse)
' Here you would check the dependencyResponse.EntityCollection property
' and act as appropriate. However, we know there is exactly one
' dependency so this example deals with it directly and deletes
' the previously created attribute.
Dim deleteAttributeRequest As DeleteAttributeRequest =
New DeleteAttributeRequest With {
.EntityLogicalName = Contact.EntityLogicalName,
.LogicalName = "sample_examplepicklist"
}
_serviceProxy.Execute(deleteAttributeRequest)
Console.WriteLine("Referring attribute deleted.")
'#End Region ' How to delete attribute
'#Region "How to delete global option set"
' Finally, delete the global option set. Attempting this before deleting
' the picklist above will result in an exception being thrown.
Dim deleteRequest As DeleteOptionSetRequest =
New DeleteOptionSetRequest With {
.Name = _globalOptionSetName
}
_serviceProxy.Execute(deleteRequest)
참고 항목
Microsoft Dynamics CRM 2015용 사용자 지정에 대한 개발자 가이드
메타데이터 모델 확장
전역 옵션 집합 옵션 삽입, 업데이트, 삭제 및 순서 지정
전역 옵션 집합 메시지
전역 옵션 집합 메타데이터 값
샘플: 전역 옵션 집합 만들기
샘플: 전역 옵션 집합 사용
샘플: 파일에 전역 옵션 집합 정보 덤프
© 2017 Microsoft. All rights reserved. 저작권 정보