2016-08-25 5 views
1

完全に新しいフィールドを作成する方法はありますか?のエンティティは、プラグインまたはWebサービス(そしてビューに関連付ける)?CRMフィールドをプログラムで登録する

私はインターネットを見渡しましたが、何も見つかりませんでした。

答えて

1

CRMメタデータを変更するには、CreateAttributeRequestを実行する必要があります。

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); 

このコードはテストされていないが、例えばリンクからつなぎ合わせているので、うまくいけば動作するはずです。

2

CreateAttributeRequestを使用して、目的のメタデータを持つ新しい属性を作成します。

ビューにプログラムで追加するのは簡単ではありません。 Layout XML要素を編集し、新しく作成した属性を追加する必要があります。 This answer should help you get started with it.

+0

私は(ビューに関連付けるために)掘り下げるべきことはありますか? –

+0

@ R.Matveevは初めてリンクを間違って追加しました。 – dynamicallyCRM

+0

SOAPまたはREST/ODataは役に立ちますか? –

関連する問題