Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Dynamics CRM ( 365 ) Option Set associating problem

Posted on by 10

Hi

I'm trying to define an entity with all of it attributes , one them is an option set , and i want to define it as a "local option set", any idea of how to do this ? 
here is my http request  : (i'm using dynamics 365 v9.0 on premise ) :

======================================================================================

POST /api/data/v9.0/EntityDefinitions HTTP/1.1


{
"@odata.type": "Microsoft.Dynamics.CRM.EntityMetadata",
"Attributes": [
{
"AttributeType": "String",
"AttributeTypeName": {
"Value": "StringType"
},
"Description": {
"@odata.type": "Microsoft.Dynamics.CRM.Label",
"LocalizedLabels": [
{
"@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
"Label": "",
"LanguageCode": 1033
}
]
},
"DisplayName": {
"@odata.type": "Microsoft.Dynamics.CRM.Label",
"LocalizedLabels": [
{
"@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
"Label": "new_name",
"LanguageCode": 1033
}
]
},
"IsPrimaryName": true,
"RequiredLevel": {
"Value": "None",
"CanBeChanged": true,
"ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
},
"SchemaName": "pt_mamadoo",
"@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
"FormatName": {
"Value": "Text"
},
"MaxLength": 100
},
{
"SchemaName": "new_myOptionSet",
"AttributeType": "Picklist",
"AttributeTypeName": {
"Value": "PicklistType"
},
"@odata.type": "Microsoft.Dynamics.CRM.OptionSetMetadata",
"IsCustomOptionSet": true,
"SourceType": 1,
"IsGlobal": false,
"Name": "new_MyOptionSet",
"OptionSetType": "Picklist",

"DisplayName": {
"@odata.type": "Microsoft.Dynamics.CRM.Label",
"LocalizedLabels": [
{
"@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
"Label": "my Option Set",
"LanguageCode": 1033
}
]
},
"IsCustomizable": {
"Value": true,
"CanBeChanged": true,
"ManagedPropertyLogicalName": "iscustomizable"
}
}
],
"Description": {
"@odata.type": "Microsoft.Dynamics.CRM.Label",
"LocalizedLabels": [
{
"@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
"Label": "",
"LanguageCode": 1033
}
]
},
"DisplayCollectionName": {
"@odata.type": "Microsoft.Dynamics.CRM.Label",
"LocalizedLabels": [
{
"@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
"Label": "my Entities",
"LanguageCode": 1033
}
]
},
"DisplayName": {
"@odata.type": "Microsoft.Dynamics.CRM.Label",
"LocalizedLabels": [
{
"@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
"Label": "My Entity",
"LanguageCode": 1033
}
]
},
"HasActivities": false,
"HasNotes": false,
"IsActivity": false,
"OwnershipType": "UserOwned",
"SchemaName": "new_MyCustomEntity"
}

======================================================================

and this is the Error i get when post this request : 

{
"error": {
"code": "0x0",
"message": "An error occurred while validating input parameters: Microsoft.OData.ODataException: An resource with type 'Microsoft.Dynamics.CRM.OptionSetMetadata' was found, but it is not assignable to the expected type 'Microsoft.Dynamics.CRM.AttributeMetadata'. The type specified in the resource must be equal to either the expected type or a derived type.\r\n at Microsoft.OData.ValidationUtils.ValidateEntityTypeIsAssignable(IEdmEntityTypeReference expectedEntityTypeReference, IEdmEntityTypeReference payloadEntityTypeReference)\r\n at Microsoft.OData.ReaderValidationUtils.ResolveAndValidateTargetTypeStrictValidationEnabled(EdmTypeKind expectedTypeKind, IEdmTypeReference expectedTypeReference, IEdmType payloadType)\r\n at Microsoft.OData.ReaderValidationUtils.ResolveAndValidateNonPrimitiveTargetType(EdmTypeKind expectedTypeKind, IEdmTypeReference expectedTypeReference, EdmTypeKind payloadTypeKind, IEdmType payloadType, String payloadTypeName, IEdmModel model, Func`3 clientCustomTypeResolver, Boolean throwIfTypeConflictsWithMetadata)\r\n at Microsoft.OData.ReaderValidationUtils.ResolvePayloadTypeNameAndComputeTargetType(EdmTypeKind expectedTypeKind, Nullable`1 expectStructuredType, IEdmType defaultPrimitivePayloadType, IEdmTypeReference expectedTypeReference, String payloadTypeName, IEdmModel model, Func`3 clientCustomTypeResolver, Boolean throwIfTypeConflictsWithMetadata, Boolean enablePrimitiveTypeConversion, Func`1 typeKindFromPayloadFunc, EdmTypeKind& targetTypeKind, ODataTypeAnnotation& typeAnnotation)\r\n at Microsoft.OData.ReaderValidator.ResolvePayloadTypeNameAndComputeTargetType(EdmTypeKind expectedTypeKind, Nullable`1 expectStructuredType, IEdmType defaultPrimitivePayloadType, IEdmTypeReference expectedTypeReference, String payloadTypeName, IEdmModel model, Func`1 typeKindFromPayloadFunc, EdmTypeKind& targetTypeKind, ODataTypeAnnotation& typeAnnotation)\r\n at Microsoft.OData.ODataReaderCore.ApplyResourceTypeNameFromPayload(String resourceTypeNameFromPayload)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtResourceEndImplementationSynchronously()\r\n at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)",
"innererror": {
"message": "An error occurred while validating input parameters: Microsoft.OData.ODataException: An resource with type 'Microsoft.Dynamics.CRM.OptionSetMetadata' was found, but it is not assignable to the expected type 'Microsoft.Dynamics.CRM.AttributeMetadata'. The type specified in the resource must be equal to either the expected type or a derived type.\r\n at Microsoft.OData.ValidationUtils.ValidateEntityTypeIsAssignable(IEdmEntityTypeReference expectedEntityTypeReference, IEdmEntityTypeReference payloadEntityTypeReference)\r\n at Microsoft.OData.ReaderValidationUtils.ResolveAndValidateTargetTypeStrictValidationEnabled(EdmTypeKind expectedTypeKind, IEdmTypeReference expectedTypeReference, IEdmType payloadType)\r\n at Microsoft.OData.ReaderValidationUtils.ResolveAndValidateNonPrimitiveTargetType(EdmTypeKind expectedTypeKind, IEdmTypeReference expectedTypeReference, EdmTypeKind payloadTypeKind, IEdmType payloadType, String payloadTypeName, IEdmModel model, Func`3 clientCustomTypeResolver, Boolean throwIfTypeConflictsWithMetadata)\r\n at Microsoft.OData.ReaderValidationUtils.ResolvePayloadTypeNameAndComputeTargetType(EdmTypeKind expectedTypeKind, Nullable`1 expectStructuredType, IEdmType defaultPrimitivePayloadType, IEdmTypeReference expectedTypeReference, String payloadTypeName, IEdmModel model, Func`3 clientCustomTypeResolver, Boolean throwIfTypeConflictsWithMetadata, Boolean enablePrimitiveTypeConversion, Func`1 typeKindFromPayloadFunc, EdmTypeKind& targetTypeKind, ODataTypeAnnotation& typeAnnotation)\r\n at Microsoft.OData.ReaderValidator.ResolvePayloadTypeNameAndComputeTargetType(EdmTypeKind expectedTypeKind, Nullable`1 expectStructuredType, IEdmType defaultPrimitivePayloadType, IEdmTypeReference expectedTypeReference, String payloadTypeName, IEdmModel model, Func`1 typeKindFromPayloadFunc, EdmTypeKind& targetTypeKind, ODataTypeAnnotation& typeAnnotation)\r\n at Microsoft.OData.ODataReaderCore.ApplyResourceTypeNameFromPayload(String resourceTypeNameFromPayload)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtResourceEndImplementationSynchronously()\r\n at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)",
"type": "Microsoft.Crm.CrmHttpException",
"stacktrace": " at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ValidateInputParameters(ModelStateDictionary controllerModelState)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.PostEntitySetImplementation(String& entitySetName, EdmEntityObject entityObject)\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
==================================
i will appreciate it if any body could help me ! 

*This post is locked for comments

  • Suggested answer
    Reza94 Profile Picture
    Reza94 10 on at
    RE: Dynamics CRM ( 365 ) Option Set associating problem

    this is the correct request i solved my problem with helping @ketan :

    {

       "@odata.type": "Microsoft.Dynamics.CRM.EntityMetadata",

       "Attributes": [

           {

               "AttributeType": "String",

               "AttributeTypeName": {

                   "Value": "StringType"

               },

               "Description": {

                   "@odata.type": "Microsoft.Dynamics.CRM.Label",

                   "LocalizedLabels": [

                       {

                           "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",

                           "Label": "",

                           "LanguageCode": 1033

                       }

                   ]

               },

               "DisplayName": {

                   "@odata.type": "Microsoft.Dynamics.CRM.Label",

                   "LocalizedLabels": [

                       {

                           "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",

                           "Label": "new_name",

                           "LanguageCode": 1033

                       }

                   ]

               },

               "IsPrimaryName": true,

               "RequiredLevel": {

                   "Value": "None",

                   "CanBeChanged": true,

                   "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"

               },

               "SchemaName": "pt_mamadoo",

               "@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",

               "FormatName": {

                   "Value": "Text"

               },

               "MaxLength": 100

           },

           {

               "IsPrimaryName": false,

               "SchemaName": "new_myoptionsetkk",

               "AttributeType": "Picklist",

               "AttributeTypeName": {

                   "Value": "PicklistType"

               },

               "@odata.type": "Microsoft.Dynamics.CRM.PicklistAttributeMetadata",

               "SourceType": 0,

               "RequiredLevel": {

                   "Value": "None",

                   "CanBeChanged": true,

                   "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"

               },

               "IsGlobalFilterEnabled": {

                   "Value": false,

                   "CanBeChanged": true,

                   "ManagedPropertyLogicalName": "canmodifyglobalfiltersettings"

               },

               "DisplayName": {

                   "@odata.type": "Microsoft.Dynamics.CRM.Label",

                   "LocalizedLabels": [

                       {

                           "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",

                           "Label": "my Optijjjj on Set",

                           "LanguageCode": 1033

                       }

                   ]

               },

               "Description": {

                   "@odata.type": "Microsoft.Dynamics.CRM.Label",

                   "LocalizedLabels": [

                       {

                           "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",

                           "Label": "",

                           "LanguageCode": 1033

                       }

                   ]

               },

               "OptionSet": {

                   "IsGlobal": false,

                   "OptionSetType": "Picklist"

               }

           }

       ],

       "Description": {

           "@odata.type": "Microsoft.Dynamics.CRM.Label",

           "LocalizedLabels": [

               {

                   "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",

                   "Label": "",

                   "LanguageCode": 1033

               }

           ]

       },

       "DisplayCollectionName": {

           "@odata.type": "Microsoft.Dynamics.CRM.Label",

           "LocalizedLabels": [

               {

                   "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",

                   "Label": "my Entities",

                   "LanguageCode": 1033

               }

           ]

       },

       "DisplayName": {

           "@odata.type": "Microsoft.Dynamics.CRM.Label",

           "LocalizedLabels": [

               {

                   "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",

                   "Label": "My Entity",

                   "LanguageCode": 1033

               }

           ]

       },

       "HasActivities": false,

       "HasNotes": false,

       "IsActivity": false,

       "OwnershipType": "UserOwned",

       "SchemaName": "new_MyCustomEntityii"

    }

  • Reza94 Profile Picture
    Reza94 10 on at
    RE: Dynamics CRM ( 365 ) Option Set associating problem

    Thank you it helped me a lot,

    but your answer was not complete, we should add this part to the option set request:

    "OptionSet":{

                "IsGlobal": false,

                "OptionSetType": "Picklist"

               }

  • Verified answer
    NODAL Profile Picture
    NODAL 860 on at
    RE: Dynamics CRM ( 365 ) Option Set associating problem

    Hi ,

    Replace "Microsoft.Dynamics.CRM.OptionSetMetadata" with "Microsoft.Dynamics.CRM.PicklistAttributeMetadata"

    Regards,

    Ketan

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans