2016-05-04 42 views
0

我想用另一個查找字段editorial(我的公司出售教科書)來篩選查找字段products如何將查找對象值傳遞給FetchXml查詢?

我知道如何從查找對象中檢索值,但我不知道如何將它們傳遞到我的fetchXml查詢語句中。

function preFilterLookup() 
{ 
    Xrm.Page.getControl("new_editorialsearch").addPreSearch(function() { 

     var ediObject = Xrm.Page.getAttribute("new_editorialsearch").getValue(); 

     // Get the lookup Object, and extract the Value (ID and Text) 
     if(ediObject != null) 
     { 
      var ediTextValue = ediObject[0].name; 
      var ediID = ediObject[0].id; 

      // Filter products by editorial 
      fetchXml = "<filter type='and'><condition attribute='name' operator='eq' value='" + ediTextValue + "' /></filter>"; 

      // Apply the filter to the field 
      Xrm.Page.getControl("new_engpro").addCustomFilter(fetchXml); 
     }   
    }); 
} 

我知道我做錯了什麼,因爲CRM不斷告訴我,我的作用是不確定的,我看不到任何語法錯誤。

有人可以告訴我正確的方法將對象名稱和ID傳遞到fetchXml語句嗎?

+0

如果你得到的函數是未定義的錯誤,這可能不是一個問題,而是你如何調用'preFilterLookup'。在函數的開頭放入一個'console.log(「running」);'語句來確保它實際上正在執行。如果這樣做不能讓你超越駝峯,請提供你收到的錯誤信息,並讓我們知道你如何佈置該事件。 – Polshgiant

+0

最初它是'onLoad',但我把它設置爲'onChange'作'編輯',它不會給我一個錯誤,但它不會做我想要的。 'console.log(「running」)'顯示**正在運行**,所以函數正在發生。我的'fetchXml'是否正確?我是否正確傳遞數據? –

+0

我不再收到錯誤'onLoad',但它不是過濾。我在'if'語句中放置了一條日誌語句,它不顯示任何內容。即使該字段有值,'if'語句似乎也會返回'null'。難道我做錯了什麼? –

回答

0

addCustomFilter只能從addPreSearch事件中調用相同的控件。因此,請致電new_engpro,致電new_editorialsearch,致電addPreSearch

相關問題