有没有办法为实体创建一个全新的字段,例如插件或网络服务(然后与 View 关联)?
我查遍了互联网,但没有找到任何东西。
最佳答案
您将需要执行CreateAttributeRequest更改 CRM 元数据。
StringAttributeMetadata stringAttribute = new StringAttributeMetadata
{
// Set base properties
SchemaName = "new_string",
DisplayName = new Label("Sample String", _languageCode),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("String Attribute", _languageCode),
// Set extended properties
MaxLength = 100
};
CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest
{
EntityName = "contact",
Attribute = stringAttribute
};
serviceProxy.Execute(createAttributeRequest);
然后您需要Customize the Entity View 。这些信息作为记录存储在 CRM 中并由 XML 表示。这是一个创建示例,但您也可以进行更新。
string layoutXml = @"<grid name='resultset' object='2' jump='name' select='1' preview='1' icon='1'>
<row name='result' id='contactid'>
<cell name='name' width='150' />
<cell name='new_string' width='150' />
</row>
</grid>";
string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='contact'>
<order attribute='new_string' descending='false' />
<attribute name='new_string' />
<attribute name='contactid' />
</entity>
</fetch>";
SavedQuery sq = new SavedQuery
{
Name = "A New Custom Public View",
Description = "A Saved Query created in code",
ReturnedTypeCode = "contact",
FetchXml = fetchXml,
LayoutXml = layoutXml,
QueryType = 0
};
serviceProxy.Create(sq);
最后需要Publish Customizations因此用户可以进行更改。
PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
serviceProxy.Execute(publishRequest);
此代码未经测试,但由示例链接拼凑而成,因此应该可以工作。
关于c# - CRM 以编程方式创建字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39149691/