2014-09-03 40 views
0

我得到一個保存查詢Id = 00000000-0000-0000-0000-000000000000不存在當我將自定義視圖設置爲CRM 2013團隊查找時, CRM 2011CRM 2013查找中的addCustomView

// Set the Owning Team View based on the account selected 
function setOwningTeamView(entityFieldName, lookupFieldName, resetSelection) { 
    // Get the selected entity 
    var account = Xrm.Page.getAttribute(entityFieldName).getValue(); 

if (account != null) { 
    var accid = account[0].id; 
    var accname = account[0].name; 

    if (resetSelection == true) { 
     // reset old selection for Contact 
     Xrm.Page.getAttribute(lookupFieldName).setValue(null); 
    } 

    // use randomly generated GUID Id for the view 
    var viewId = "{0CBC820C-7033-4AFF-9CE8-FB610464DBD3}"; 
    var entityName = "team"; 

    // give the custom view a name 
    var viewDisplayName = "Teams applicable to " + accname + ""; 

    var accountBU = SDK.REST.retrieveRecordSync(Xrm.Page.getAttribute("a_account").getValue()[0].id, "Account", "OwningBusinessUnit", ""); 
    var relatedBusinessUnits = SDK.REST.retrieveMultipleRecordsSync("BusinessUnit", "?$select=BusinessUnitId,Name&$filter=a_Type/Value eq 1"); 
    var FetchXMLBU = ""; 
    for (var i = 0; i < relatedBusinessUnits.results.length; i++) { 
     FetchXMLBU += "<value>" + relatedBusinessUnits.results[i].BusinessUnitId + "</value>" 
    } 

    debugger; 

    // find all contacts where parent customer is the account selected and where the Contact record is active 
    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" 
     + "<entity name='team'>" 
     + "<attribute name='teamid' />" 
     + "<attribute name='name' />" 
     + "<attribute name='description' />" 
     + "<attribute name='businessunitid' />" 
     + "<filter>" 
     + "<condition attribute='businessunitid' operator='in'>" 
     + "<value>" + accountBU.OwningBusinessUnit.Id + "</value>" 
     + FetchXMLBU 
     + "</condition>" 
     + "</filter>" 
     + "</entity>" 
     + "</fetch>"; 

    // build Grid Layout 
    var layoutXml = "<grid name='resultset' " + 
     "object='1' " + 
     "jump='teamid' " + 
     "select='1' " + 
     "icon='0' " + 
     "preview='0'>" + 
     "<row name='result' id='teamid'>" + 
     "<cell name='name' width='200' />" + 
     "<cell name='businessunitid' width='200' />" + 
     "<cell name='description' width='400' />" + 
     "</row>" + 
     "</grid>"; 

    // add the Custom View to the indicated [lookupFieldName] Control 
    Xrm.Page.getControl(lookupFieldName).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true); 
    //The following line is the an unsupported way of disabling the View Picker, currently there is no supported way. 
    document.getElementById(lookupFieldName + "_i").setAttribute("disableViewPicker", "1"); 
    //document.getElementById(lookupFieldName).setAttribute("disableViewPicker", "1"); 
} 
} 

我懷疑問題是與調用SDK.REST作爲解釋in this thread,但結果accountBUrelatedBusinessUnits是正確的。

我一直在使用另一種SDK調用aith正確的行爲:

var systemUserTeam = SDK.REST.retrieveMultipleRecordsSync("TeamMembership", 
       "$select=TeamId&$filter=TeamId eq guid'" 
       + Xrm.Page.getAttribute("aux_owningteamid").getValue()[0].id 
       + "' and SystemUserId eq guid'" 
       + Xrm.Page.getAttribute("ownerid").getValue()[0].id 
       + "'"); 
    if (systemUserTeam.results.length != 1) { 

我設置了自定義fetchXMLlaoyoutXML用同樣的方法一個客戶查找視圖除了對SDK的調用。

我可以對SDK調用進行哪些​​更改以使其正常工作?

回答

2

如果您不反對重寫代碼,現在有一種更容易和支持的方式來將自定義過濾器添加到查找中。您可以使用現有視圖並應用preFilter。

This blog post提供了一個很好的例子。

+0

謝謝,我已經檢查了博客,但對我來說,因爲我需要一個自定義視圖我將不得不使用addCustomView – Jorge 2014-09-03 15:30:05

0

這可能是您的layoutxml objecttypecode爲1時的對象='1',意味着您需要在團隊中創建帳戶時嘗試創建帳戶視圖。因此,CRM正在制定針對帳戶的自定義視圖,並且他們試圖將其稱爲針對團隊。我相信我的團隊是9.這個改變應該希望其他所有的都是正確的,你有沒有排序。如果不是九,下載並安裝DynamicsXRMtools解決方案並檢查CRM元數據。

1

addCustomView不適用於Owner查找。 Owner查找用於分配用戶擁有的記錄。

鏈接 - https://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_addCustomView

+0

能否請您提供更多的信息?現在,您的帖子更多的是評論而不是真實的答案... – Badacadabra 2017-06-07 11:47:57

+0

@Badacadabra - 您可以創建一個自定義字段,系統字段「ownerid」使窗體不可見。 在自定義字段中,實現所需的「addCustomView」,並在服務器上通過插件創建「AssignRequest」。 – pennant 2017-06-09 06:56:58