c# - CRM 以编程方式创建字段

标签 c# dynamics-crm-2011

有没有办法为实体创建一个全新的字段,例如插件或网络服务(然后与 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/

相关文章:

c# - ToastContentBuilder' 不包含 'Show' 的定义

c# - 为什么 Random() 在 .Net 中以这种方式实现?

c# - 如何指定以应用程序域中立的方式加载程序集

dynamics-crm-2011 - 哪些自定义可以将 "disabled"属性添加到 Dynamics CRM 子网格上的只读用户?

javascript - 使用 javascript 从网格中获取所有行,而不仅仅是可见页面上的行

c# - 哪种 visual studio 解决方案类型适合我?

c# - 通过C#登录网站

c# - 为什么使用两个 ManualResetEvents 会导致死锁?

javascript - CrmRestKit 与 XrmServiceToolkit

c# - 如何向查找字段添加值?