解決策があります。
免責事項 このソリューションは、壮大なプロポーションの完全なハックであるため、推奨 (またはサポート) されていませんが、問題は解決しました。これは、クライアントにより適したカスタム ソリューションを構築するための一時的な機能です。そのため、ハッキングがうまくいった理由はありません。さらに、スクリプトをもっとうまく書くことができたので、それを世に出したいだけでした。
注: このソリューションでは、JQuery や CRM FetchKit などの外部ライブラリを使用します。
1) カスタム オブジェクトとアカウントへのリレーションシップの追加
カスタム エンティティがあり、アカウント エンティティからカスタム エンティティへの 1:N リレーションシップを作成しました。これにより、カスタム エンティティの関連付けられたビューを指すナビゲーション リンクをアカウント フォームに作成できます。リンクが入ったら、変更を保存して公開します。
2) 作成された新しいナビゲーション リンクの ID を取得する
上記のリンクはフォーム上にあるはずなので、保存して公開した後、ライブ ビューに移動し、IE 開発者ツールを使用してリンクの ID を取得します。 onclick を使用して、後でいくつかのことを行います。
3) 作成されたナビゲーション リンクの onclick を装飾
する id があるので、onclick をいくつかの追加機能で装飾したいと考えています。2 つの新しい Web リソースを作成します。
- "YourCustomEntity" _init : Javascript Web リソース: これはアカウント フォームのオンロードで使用され、作成したリンクを取得し、onclick を変更して追加の操作を行います。
- YourCustomEntity _page : HTML ページ Web リソース: 元の質問によると、プレビュー ペインを表示するという追加の要件があるため、標準のグリッドを使用できませんでした
"YourCustomEntity"_init の
コード コードは非常に基本的なもので、オブジェクト キャッシュなどはなく、単に問題を解決するために書かれたものです。コードにコメントを追加しました。また、Entity は一般的な名前であり、これはカスタム タイプの名前です。元の関連付けられたビューを display:none ではなく hidden に設定します。これは、リボンが更新されて読み込まれる場所であるため、バックグラウンドで読み込む必要があるためです。これを行うためのスクリプトが確実に実行されています。だから私たちはそれを使うことができます:)
function previewEntityInit(){
//Catch any navigation link click, we need this because we need to hide our
//grid when we are not on the custom entity page
$('.ms-crm-Nav-Subarea-Link, .ms-crm-FormSelector-SubItem').click(function () {
//Get the id of the link clicked and the frame injected object
var id = $(this).attr('id'),
cFrame = $('#entity_frame_preview');
//if the frame has already been injected
if(cFrame.length !== 0) {
//If we are not in the correct section
//(i.e. activities nav link was clicked) hide it
if (id !== 'nav_new_account_new_entity') {
cFrame.attr('style', 'display:none;');
}
else{
//The correct link was clicked, so show it
cFrame.attr('style', 'display:block; width:100%; height:100%;');
$('#new_account_new_entityFrame').attr('style', 'visibility: hidden;');
}
}
else{
//This is the first time the correct link has been clicked
//So we hide the default associated view and inject our
//own iframe point to the YourCustomEntity_page embedded resource we created
var src = Xrm.Page.context.getServerUrl();
if (id === 'nav_new_account_new_entity') {
$('#new_account_new_entityFrame').attr('style', 'visibility: hidden;');
$('<iframe />', {
id: 'entity_frame_preview',
src: src + '/WebResources/new_entity_page',
width: '100%',
height: '100%'
}).prependTo('#tdAreas');
}
}
});
YourCustomEntity_page
ここにすべてのコードを表示するつもりはありませんが、次のリンクに基づいています。
プレビュー フォーム リンク
次のように変更しました。
- ビュー名のみがハードコードで、残りはコードを介して取得されます (以下のコード)
- これをロードする単純な HTML セクションを使用する代わりに、2 番目の iframe の選択を使用しません (このコードと以下のロード関数)。
ハードコーディングされた値なし
var server = Xrm.Page.context.getServerUrl();
var orgName = "";
// grid related settings
var entityId = window.parent.Xrm.Page.data.entity.getId();
var entityType = "1";
var areaView = "new_account_new_entity";
var internalGridElement = "crmGrid_new_account_new_entity";
var timeoutKey = null;
プレビュー用の HTML
<div id="previewForm" style="display: none;">
<ol>
<li><span class="lbl">Account:</span><span id="lblAccount"></span></li>
<li><span class="lbl">Created:</span><span id="lblDate"></span></li>
<li><span class="lbl">Regarding:</span><span id="lblRegarding"></span></li>
<li><span class="lbl">Owner:</span><span id="lblOwner"></span></li>
</ol>
<div id="subject">
<span class="lbl">Subject:</span><span id="lblSubject" class="value"></span>
</div>
<div>
<span id="lblMsg"></span>
</div>
</div>
LoadPreview コード
これは、CRMFetchKit と呼ばれる外部ライブラリを使用します。コードは実際には 3 つのフェッチ呼び出しを実行します。これは理想的ではなく、実際には 1 つにする必要があります (結合を使用して、Google で検索してください:))。すぐにマネージド ソリューションに置き換えられます。
function LoadPreviewPane(entity) {
if (entity != null) {
$('#previewForm').show();
var fetchxml = ['<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">',
' <entity name="new_entity">',
'<attribute name="subject" />',
'<attribute name="description" />',
'<attribute name="createdon" />',
'<attribute name="new_account" />',
'<attribute name="ownerid" />',
' <filter type="and">',
' <condition attribute="activityid" operator="eq" value="' + entity.Id + '" />',
' </filter>',
' </entity>',
'</fetch>'].join('');
CrmFetchKit.Fetch(fetchxml).then(function (results) {
var account = window.parent.Xrm.Page.getAttribute("name").getValue(),
subject = results[0].getValue('subject'),
desc = results[0].getValue('description'),
created = new Date(results[0].getValue('createdon')),
theDate = created.getDate() + "/" + (created.getMonth() + 1) + "/" + created.getFullYear(),
owner = '',
regarding = '';
var fetchxml2 = ['<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">',
' <entity name="systemuser">',
'<attribute name="fullname" />',
' <filter type="and">',
' <condition attribute="systemuserid" operator="eq" value="' + results[0].getValue('ownerid') + '" />',
' </filter>',
' </entity>',
'</fetch>'].join('');
CrmFetchKit.Fetch(fetchxml2).then(function (users) {
owner = users[0].getValue('fullname');
$('#lblOwner').html(owner);
});
var fetchxml3 = ['<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">',
' <entity name="account">',
'<attribute name="name" />',
' <filter type="and">',
' <condition attribute="accountid" operator="eq" value="' + results[0].getValue('new_accountname') + '" />',
' </filter>',
' </entity>',
'</fetch>'].join('');
CrmFetchKit.Fetch(fetchxml3).then(function (regardings) {
regarding = regardings[0].getValue('name');
$('#lblRegarding').html(regarding);
});
$('#lblAccount').html(account);
$('#lblSubject').html(subject);
$('#lblMsg').html(nl2br(desc));
$('#lblDate').html(theDate);
});
}
}