smemo

技術メモです。

左外部結合(Left join)のビューを作成

今回は左外部結合のビューを作成する手順のメモ。

DynamicsのGUIからは左外部結合のビューは作成できないと思います。なので活動を一度も行ったことのない取引先企業の抽出を行うなどの、参照先エンティティ(取引先企業)を軸にしながら参照元(活動)が存在しないレコードを抽出するようなビューを作成することはできなかったと思います。

ただ、ビューの構成情報を管理しているxml(customizations.xml)を修正することで左外部結合のビューを作成することができました。

注意点としては作成したビューの検索条件はGUIから変更できないこと、高度な検索でビューが選択できなかったこと。


以下のMSDNを参考にしました。
左外部結合を FetchXML で使用して "存在しない" 記録をクエリする
 

以下にも保存済みクエリの編集をサポートすると記載がありました
カスタマイズ ファイルを編集するとき


以下手順のメモです。

1.ビューを作成(既存のビューを使用しても構いません。)

2.変更したいビューを含むソリューションをエクスポート

3.エクスポートしたソリューション内のcustomizations.xmlをエディタまたはVisualStudioで開く。(VisualStudioを使用する場合はスキーマファイルでXMLの編集補助機能を使用することが可能です。)

4.変更対象のビューを探す(ビュー名などで検索すればヒットすると思います。)

5.以下変更手順です。今回は「Test」という名前のビューを作成しました。

変更前

<savedquery>
  <IsCustomizable>1</IsCustomizable>
  <CanBeDeleted>1</CanBeDeleted>
  <isquickfindquery>0</isquickfindquery>
  <isprivate>0</isprivate>
  <isdefault>0</isdefault>
  <returnedtypecode>1</returnedtypecode>
  <savedqueryid>{8c5628d0-4cbd-e611-80f9-c4346bc4df84}</savedqueryid>
  <layoutxml>
    <grid name="resultset" object="1" jump="name" select="1" preview="1" icon="1">
      <row name="result" id="accountid">
        <cell name="name" width="150" />
        <cell name="address1_composite" width="100" disableSorting="1" />
        <cell name="address1_telephone1" width="100" />
        <cell name="emailaddress1" width="100" />
      </row>
    </grid>
  </layoutxml>
  <querytype>0</querytype>
  <fetchxml>
    <fetch version="1.0" output-format="xml-platform" mapping="logical">
      <entity name="account">
        <attribute name="name" />
        <order attribute="name" descending="false" />
        <attribute name="emailaddress1" />
        <attribute name="address1_telephone1" />
        <attribute name="address1_composite" />
        <attribute name="accountid" />
      </entity>
    </fetch>
  </fetchxml>
  <IntroducedVersion>1.0.0.0</IntroducedVersion>
  <LocalizedNames>
    <LocalizedName description="Test" languagecode="1041" />
  </LocalizedNames>
</savedquery>

変更後

<savedquery>
  <IsCustomizable>1</IsCustomizable>
  <CanBeDeleted>1</CanBeDeleted>
  <isquickfindquery>0</isquickfindquery>
  <isprivate>0</isprivate>
  <isdefault>0</isdefault>
  <returnedtypecode>1</returnedtypecode>
  <savedqueryid>{8c5628d0-4cbd-e611-80f9-c4346bc4df84}</savedqueryid>
  <layoutxml>
    <grid name="resultset" object="1" jump="name" select="1" preview="1" icon="1">
      <row name="result" id="accountid">
        <cell name="name" width="150" />
        <cell name="address1_composite" width="100" disableSorting="1" />
        <cell name="address1_telephone1" width="100" />
        <cell name="emailaddress1" width="100" />
      </row>
    </grid>
  </layoutxml>
  <querytype>0</querytype>
  <fetchxml>
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
      <entity name="account">
        <attribute name="name" />
        <order attribute="name" descending="false" />
        <attribute name="emailaddress1" />
        <attribute name="address1_telephone1" />
        <attribute name="address1_composite" />
        <attribute name="accountid" />
<!-- 追加 start -->
        <link-entity name="appointment" from="regardingobjectid" to="accountid"  alias="ab" link-type="outer">
        </link-entity>
        <filter type="and">
          <condition entityname="ab" attribute="regardingobjectid" operator="null" />
        </filter>
<!-- 追加 end -->
      </entity>
    </fetch>
  </fetchxml>
  <IntroducedVersion>1.0.0.0</IntroducedVersion>
  <LocalizedNames>
    <LocalizedName description="Test" languagecode="1041" />
  </LocalizedNames>
</savedquery>

変更が完了したらソリューションをインポートしてカスタマイズの公開で完了です。

では確認です。現在表示されているレコードはこちら。
f:id:smemo:20161208232756p:plain

コントソ商店に予定を作成
f:id:smemo:20161208233351p:plain

ビューを確認。コントソ商店が消えている(予定が登録されたため)
f:id:smemo:20161208233042p:plain


GUIでのビューの条件変更はできなくなりますが、要件によっては使える機能ではないかと感じました。


以上です。