Search code examples
dynamics-crmmicrosoft-dynamicsuci

D365 - UCI - A validation error occurred. The value 895390001 of 'MULTISELECT' on record of type ENTITY' is outside the valid range. Accepted Values:


I am trying to use the Multiselect option set and want to build it dynamically, the addOption() is populating the multiselect field correctly, but on save of record it is prompting the validation error.

On change of contact lookup, I am populating the abc_multiselect field. It is populating fine dynamically then user selects the required options from multiselect field, but on save of record (Ribbon Save button not custom save event of form) the CRM is not accepting the values.

MSCRM Version
Server version: 9.2.22081.00182 
Client version: 1.4.4647-2208.1
function polulate(executionContext){
   var formContext = executionContext.getFormContext();
   var multiselect = formContext.getControl("abc_multiselect");
   var high = {value : 895390001, text : "High"};
   multiselect.addOption(high);
}

The error is;

On Popup

One or more of the option values for this picklist are not in the range of allowed values.

Details

Exception Message: A validation error occurred. The value 895390001 of 'abc_multiselect' on record of type 'abc_ENTITY' is outside the valid range. Accepted Values: 

ErrorCode: -2147204326
HexErrorCode: 0x8004431a

ErrorDetails: 
    ApiExceptionSourceKey: Plugin/Microsoft.Crm.ObjectModel.TargetAttributeValidationPlugin
    ApiStepKey: fc743e7d-fbea-4695-bdb9-7d78334c8474
    ApiDepthKey: 1
    ApiActivityIdKey: 3907c6d7-ef4a-437e-946f-55e0f956fc3e
    ApiPluginSolutionNameKey: System
    ApiStepSolutionNameKey: System
    ApiExceptionCategory: ClientError
    ApiExceptionMessageName: PicklistValueOutOfRange
    ApiExceptionHttpStatusCode: 400

HelpLink: http://go.microsoft.com/fwlink/?LinkID=398563&error=Microsoft.Crm.CrmException%3a8004431a&client=platform

TraceText: 
    [Microsoft.Crm.ObjectModel: Microsoft.Crm.ObjectModel.TargetAttributeValidationPlugin]
    [fc743e7d-fbea-4695-bdb9-7d78334c8474: TargetAttributeValidationPlugin]

Activity Id: 28d5f67f-bf24-4eca-9124-cf95cf06dc30

I also tried to make all option set values hard coded (Added during the multiselect field creation), it worked smoothly. No issue ! But on dynamically population; on save, the CRM is not accepting the values.

I have tried this , this, this and this but all in vain.

Any one can guide, what is missing?

Update 1

function polulate(executionContext){
   var formContext = executionContext.getFormContext();
   var multiselect = formContext.getControl("abc_multiselect");
   multiselect.clearOptions();
   var high = {value : 895390001, text : "High"};
   multiselect.addOption(high);
}

I also checked by changing the value from 895390001 to 895390000 and even to 100 and 101 but still same issue.


Solution

  • For using addOption those options need to be there in metadata first. You cannot add an option that is not present in metadata. Example can be Suppose you have Option A, 1 and 3 in Metadata. now you want to add another option 4 using Javascript "addOption", it is not possible.

    In your case, get a maximum possible set or options in the optionset now onload of form or Onchange of field "removeOption " the options that are not required.