2012-12-12 18 views
0

我正在爲CRM 2011進行自定義。我創建了一個自定義實體(基於活動,因此也是活動類型),創建了與帳戶的關係帳戶表單創建了一個自定義導航鏈接,指向一個Web資源,這將自定義顯示(這只是一個JavaScript頁面)。單擊自定義導航鏈接時顯示活動選項卡

使用Web資源而不是標準關係鏈接,因爲它正在執行列表和預覽顯示,而不僅僅是開箱即用功能提供的列表視圖。

我想要做的是在帳戶表單上顯示活動選項卡(活動功能區選項卡),每當按下自定義導航鏈接並且用戶進入該部分時,與您點擊時顯示的方式相同活動導航鏈接。我似乎無法找到關於Tab Display Rules的很多信息,因爲我認爲這是應該完成的地方(如果可能的話)。另外,如果有JavaScript方法(雖然我還沒有找到),那麼這也可以。

+0

我不明白,你希望你的自定義導航鏈接打開活動網格? –

+0

嗨,詹姆斯,我有一個鏈接,它鏈接到嵌入式資源,它只是一個Javascript頁面的HTML頁面,所有的作品。我需要做的事情還是在顯示嵌入式資源時顯示活動功能區選項卡。 – Modika

+0

我不認爲那將是可能的。 –

回答

2

我們有一個解決方案。

免責聲明不推薦使用這種溶液(或支持),因爲它是一個百年難遇的完全破解,但它解決了問題我們。這只是一個暫時的功能,因爲我們構建了一個更適合客戶端的自定義解決方案,所以它不會在前進,這就是黑客爲我們工作的原因。另外,腳本可以寫的更好,我們只是想把它推出去。

注:該解決方案將使用一些外部庫如jQuery & CRM FetchKit

1)添加到自定義對象的關係和賬戶 我們有一個自定義實體,和我們創建了一個1 :從帳戶實體到我們的自定義實體的N關係。這樣做可以讓我們做的是在帳戶表單上創建一個導航鏈接,該鏈接指向我們自定義實體的關聯視圖。鏈接進入後,我們保存併發布更改。

2)獲得新的導航鏈接的ID創建 上面的鏈接現在應該是這樣的形式,所以保存和發佈後,我們去現場查看,並使用IE的開發工具,我們得到的id鏈接,因爲我們需要趕上onclick並稍後做一些事情。

3)裝飾的導航鏈接的onclick創建 我們有ID,以便我們要裝點一些附加功能的onclick。我們創建了2個新的網絡資源:

  • 「YourCustomEntity」 _init:JavaScript網絡資源:這將在賬戶形式的onload被用來獲得我們創建的鏈接,改變的onclick做一些額外的事情
  • YourCustomEntity _page:HTML頁面的Web資源:按照原來的問題,我們有一個顯示預覽窗格這就是爲什麼我們不能使用標準網格

代碼的附加要求對於「YourCustomEntity」_init 代碼是非常基本的,並沒有任何對象緩存或類似的東西,它只是爲了解決我們的問題。我已經添加了對代碼的評論。實體也是一個通用名稱,這是我們自定義類型的名稱。我們將原始相關視圖設置爲隱藏,而不是顯示:無,因爲我們仍然需要將其添加到背景中,因爲這是功能區得到更新和加載的位置,所以肯定有一些腳本正在執行此操作,希望我們知道它因此,我們可以只使用:)

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 不打算在這裏顯示所有的代碼,但我們根據我們的這個鏈接:

Preview Form Link 我們在以下幾個方面改變了它:

  • 只有視圖名稱是硬編碼,其餘的是通過代碼(下面的代碼)
  • 我們不使用第二個iframe選擇,而是有一個簡單的HTML部分加載它(代碼爲這個和我們的加載函數以下)

沒有硬編碼值

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外部庫。該代碼實際上做了三次調用,這不是理想的,它應該是一個真正的(使用連接,谷歌它:)),但這是不工作,拖動,所以我們決定只與三個,因爲這整個部分將盡快替換爲受管理的解決方案。

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

       }); 
      } 
     } 
+0

+1和上傳解決方案的榮譽,並承認其不受支持! –

相關問題