创建Dataverse自定义属性时,如何设置只读的IsSearchable属性?
Dataverse自定义字符串属性IsSearchable设置问题解决
问题原因
IsSearchable是Dataverse的只读计算属性,无法直接赋值,它的取值由以下三个条件共同决定:
- 字符串属性的
MaxLength≤ 4000(多行文本属性长度超过4000时默认不可搜索) IsValidForSearch设为trueIsValidForAdvancedFind设为true
你之前的代码缺少MaxLength和IsValidForSearch的配置,因此即使设置了IsValidForAdvancedFind,系统仍会将IsSearchable设为false。
修改后的代码示例
attribute = new StringAttributeMetadata { // 注意SchemaName不能包含空格,需符合Dataverse命名规范(如自定义前缀+属性名) SchemaName = "new_solutionattribute", DisplayName = new Label("Attribute name", 1036), RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.ApplicationRequired), Description = new Label("Description", 1036), IsAuditEnabled = new BooleanManagedProperty(true), IsValidForAdvancedFind = new BooleanManagedProperty(true), IsValidForForm = true, // 添加IsValidForSearch配置 IsValidForSearch = new BooleanManagedProperty(true), // 设置≤4000的长度值,根据业务需求调整 MaxLength = 100, IsSecured = false }; CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest { EntityName = "TableName", Attribute = attribute }; createAttributeRequest["SolutionUniqueName"] = "SolutionUniqueName"; // ServiceClient _serviceClient已连接 _serviceClient.Execute(createAttributeRequest);
额外注意事项
- SchemaName必须是合法标识符,不能包含空格、特殊字符,建议使用自定义解决方案前缀(如
new_)避免命名冲突。 - 如果需要创建多行文本属性(MaxLength>4000),则IsSearchable始终为false,此类属性无法被搜索。
内容的提问来源于stack exchange,提问作者EugeneDelage
相关产品推荐
相关产品推荐

