2013-05-02 74 views
0

我有一點讓我瘋狂的要求: 我們有8種不同的聯繫實體形式。 我們也有8個選項的選擇列表。 這個想法是基於選擇的選項,我們可以打開該聯繫人記錄默認情況下顯示一個特定的形式,而不使用JAVASCRIPT,以避免性能問題(每個記錄必須加載兩次)。例如:Crm 2011 - 如何根據屬性值設置默認表單(不使用Javascript)?

形式:
形式1
形式2
形式3

提貨單值 - 缺省形式:

形式1
形式2
形式3

如果選擇表格3(選擇列表值),然後在我下次打開該記錄時,應顯示錶格3默認。

如果選擇表單1(選擇列表值),那麼下次打開該記錄時,表單1應默認顯示。

我已經在systemform實體上托盤註冊了一個插件,在RetrieveFilteredForms消息中,更新了userentityuisettings表,並且我已經能夠設置每次打開記錄時顯示的「DEFAULT」,而不管最後打開的窗體。

我已經在聯繫實體中托盤註冊一個插件,在Retrieve消息中,更新了userentityuisettings表,但是我發現Crm只查閱表格一旦如果沒有屬性更新,下面的時間Crm採用默認表單從緩存中打開值。

回答

0

編輯:OP後指定,他需要一個解決方案沒有javascript,我離開這個答覆爲未來的參考。

您可以使用javascript,在OnLoad事件中檢查選取列表值並導航到所需的表單。查看此代碼作爲示例

var value = Xrm.Page.getAttribute("new_optionset").getValue(); 

switch(value) { 
case 100000000: 
    Xrm.Page.ui.formSelector.items.get(0).navigate(); 
    break; 
case 100000001: 
    Xrm.Page.ui.formSelector.items.get(1).navigate(); 
    break; 
case 100000002: 
    Xrm.Page.ui.formSelector.items.get(2).navigate(); 
    break; 
/// ... other cases here 
default: 
    // default form to open when there is no value 
    Xrm.Page.ui.formSelector.items.get(0).navigate(); 
} 
+0

感謝您的回答。這實際上是我們處理這種權利的方式。但是由於表單必須加載兩次,所以存在性能問題。我想知道是否有另一種方式(可能與插件)使用JavaScript來實現這一點。 – 2013-05-02 16:12:59

+0

我明白,請在您的問題中添加此信息,因爲這是相關的。 – 2013-05-02 16:16:13

+0

我已經添加了該信息。我的壞Guido。感謝您的建議 – 2013-05-02 16:20:48

3

這是一個古老的問題,但由於它是在我的搜索這個問題中出現,我想添加我的解決方案。

我們使用Dynamics CRM 2013.據我所知,2011年後期版本也支持這種技術。

實體打開時顯示的表單由幾件事決定 - 表單的默認表單,安全角色和備用設置以及當前用戶爲該實體使用的最後一個表單。我們遇到了一個類似的問題,我們希望根據表單的值顯示不同的帳戶表單。我們也厭倦了JavaScript技術需要不斷重新加載/刷新。

我發現了一些博客帖子(特別是這一個:http://gonzaloruizcrm.blogspot.com/2014/11/avoiding-form-reload-when-switching-crm.html),它提到可以編寫一個插件到實體的Retrieve中,允許您從UserEntityUISettings中讀取值(LastViewedFormXml)最後一次使用。如果它不是你想要的形式,你可以寫入所需的值。這可以避免javascript窗體刷新。

我不得不修改我發現的樣本中的一些代碼以使其起作用,但我對結果感到滿意。您需要使用CrmSvcUtil生成一個實體類並將其包含在項目中。您可以從表單編輯器的網址獲取表單guid。

using System; 
using System.Collections.ObjectModel; 
using System.Globalization; 
using System.Linq; 
using System.ServiceModel; 
using System.ServiceModel.Description; 

using Microsoft.Xrm.Sdk; 
using Microsoft.Xrm.Sdk.Messages; 
using Microsoft.Xrm.Sdk.Query; 
using Microsoft.Xrm.Sdk.Client; 

namespace CRM.Plugin.AccountFormSwitcher 
{ 
    public class Plugin : IPlugin 
    { 
     public enum accountType 
     { 
      Customer = 100000000, 
      Vendor =  100000001, 
      Partner = 100000002, 
      Other = 100000003 
     } 

     public const string CustomerAccountFormId = "00000000-E53C-4DF4-BC99-93856EDD168C"; 
     public const string VendorAccountFormId = "00000000-E49E-4197-AB5E-F353EF0E806E"; 
     public const string PartnerAccountFormId = "00000000-B8C6-4E2B-B84E-729AA11ABE61"; 
     public const string GenericAccountFormId = "00000000-8F42-454E-8E2A-F8196B0419AF"; 

     public const string AccountTypeAttributeName = "cf_accounttype"; 

     public void Execute(IServiceProvider serviceProvider) 
     { 
      if (serviceProvider == null) 
      { 
       throw new ArgumentNullException("serviceProvider"); 
      } 

      // Obtain the execution context from the service provider. 
      IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); 

      ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); 

      IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); 
      IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); 

      var pluginContext = (IPluginExecutionContext)context; 
      if (pluginContext.Stage == 20) //pre-operation stage 
      { 
       var columns = (ColumnSet)pluginContext.InputParameters["ColumnSet"]; 
       if (!columns.Columns.Contains(AccountTypeAttributeName)) 
        columns.AddColumn(AccountTypeAttributeName); 
      } 
      else if (pluginContext.Stage == 40) //post-operation stage 
      { 
       EntityReference currentEntity = (EntityReference)context.InputParameters["Target"]; 
       if (currentEntity == null) 
        return; 

       var query = new QueryExpression(Account.EntityLogicalName); 
       query.Criteria.AddCondition("accountid", ConditionOperator.Equal, currentEntity.Id); 
       query.ColumnSet = new ColumnSet(AccountTypeAttributeName); 
       var accounts = service.RetrieveMultiple(query).Entities; 
       Account currentAccount = (Account)accounts[0]; 

       SetForm(currentAccount, service, context.UserId); 
      } 
     } 

     private void SetForm(Account account, IOrganizationService service, Guid userId) 
     { 
      var query = new QueryExpression(UserEntityUISettings.EntityLogicalName); 
      query.Criteria.AddCondition("ownerid", ConditionOperator.Equal, userId); 
      query.Criteria.AddCondition("objecttypecode", ConditionOperator.Equal, Account.EntityTypeCode); 
      query.ColumnSet = new ColumnSet("lastviewedformxml"); 
      var settings = service.RetrieveMultiple(query).Entities; 

      // Some users such as SYSTEM have no UserEntityUISettings, so skip. 
      if (settings == null || settings.Count != 1 || account.cf_AccountType == null) return; 

      var setting = settings[0].ToEntity<UserEntityUISettings>(); 
      string formToUse; 
      switch ((accountType)account.cf_AccountType.Value) 
      { 
       case accountType.Customer: 
        formToUse = String.Format("<MRUForm><Form Type=\"Main\" Id=\"{0}\" /></MRUForm>", CustomerAccountFormId); 
        break; 
       case accountType.Vendor: 
        formToUse = String.Format("<MRUForm><Form Type=\"Main\" Id=\"{0}\" /></MRUForm>", VendorAccountFormId); 
        break; 
       case accountType.Partner: 
        formToUse = String.Format("<MRUForm><Form Type=\"Main\" Id=\"{0}\" /></MRUForm>", PartnerAccountFormId); 
        break; 
       case accountType.Other: 
        formToUse = String.Format("<MRUForm><Form Type=\"Main\" Id=\"{0}\" /></MRUForm>", GenericAccountFormId); 
        break; 
       default: 
        formToUse = String.Format("<MRUForm><Form Type=\"Main\" Id=\"{0}\" /></MRUForm>", GenericAccountFormId); 
        return; 
      } 

      // Only update if the last viewed form is not the one required for the given opportunity type 
      if (!formToUse.Equals(setting.LastViewedFormXml, StringComparison.InvariantCultureIgnoreCase)) 
      { 
       var s = new UserEntityUISettings { Id = setting.Id, LastViewedFormXml = formToUse }; 
       service.Update(s); 
      } 
     } 
    } 
} 

而且它只是諮詢UserEntityUISettings一旦解決了提問者的問題,我不知道爲什麼會發生的事情。但是,當觸發屬性更改時,爲什麼不使用javascript更改表單?我所做的和我沒有遇到任何問題,插件不顯示所需的。

+0

我試圖讓這個工作沒有運氣。註冊插件後,您是否創建了一個「步驟」,並將其設置爲運行預操作同步? (我正在使用CRM 2016) – cmartin 2017-03-17 19:23:08

0

這是一個古老但很好的...我使用CRM規則來生成隱藏標籤和顯示標籤操作,實質上顯示每個用戶角色的不同形式。

步驟:

  1. 創建一個龐大的形式與所有你想要顯示(如果你已經有很多形式,這將包括所有形式的所有字段)的字段。
  2. 將表單組織成TABS,每個標籤顯示「一種形式」的數據。 (您也可以爲每個用戶組設置多個TABS)。通常情況下,我創建了一個「常規」選項卡,其中包含用於設置表單其餘部分的關鍵選項集,以及角色/用戶組/表單中常見的任何字段,例如狀態,名稱等... 3 )通過取消選中管理UI中這些選項卡表單屬性窗體上的可見框,隱藏除「常規」選項卡之外的所有選項卡。 4)使用CRM規則(crm-rules.com),你可以帶入元數據,表單以及所有的標籤和部分。然後你只需要編寫一個規則每個「形式」您要顯示...每個規則是這樣的格式:

    • IF USER_ROLE包含「銷售」,那麼顯示標籤:銷售
    • IF USER_ROLE包含「營銷」,那麼顯示標籤:營銷

你也可以做到這一點,當然,有一個選項設置,或形式爲條件......一個這樣的好處在任何領域方法是如果用戶跨越角色邊界(或者某些用戶是可以訪問多個表單的安全角色的一部分),這一技術顯示他們這兩種形式在一次...

HTH人,CRM規則(www.crm-rules.com)生成JavaScript來做到這一點...