0

我正在處理CRM 2015中的「註冊採用」表單,具體涉及三個字段;產品,組件和編輯。 '產品'是引用產品實體的查找字段。 '組件'和'社論'是簡單的文本字段,使用JavaScript填充。產品實體中的每個產品都有一個相應的組件和編輯,它們是產品表單中的選項集。如何使用與單個查找字段相關的信息填充字段?

目標: 我想要一個觸發OnChange功能的'產品',查看特定的產品記錄,獲取其相應的組件和編輯信息,並自動填充'組件'和'編輯'註冊採用'。

問題: 我似乎無法弄清楚如何從「產品」查找字段的值,並用它來獲得我需要的信息

下面是一段代碼我已經被測試:

function populateProduct(blank) 
{ 
    if (blank != null || blank != undefined) 
    { 
     var productName; 
     var product = Xrm.Page.getAttribute(blank); 
     if (product.getValue != null || product.getValue != undefined) 
     { 
      productName = product.getValue()[0].name; 
      console.log("the product name is " + productName); 
      var componentXml = "<fetch mapping='logical'>"+"<entity name='product'>"+"<attribute name='new_component'/>"+"<filter>"+"<condition attribute = 'name' operator='eq' value='"+productName+"' />"+"</filter>"+"</entity>"+"</fetch>"; 
      var fetchComponent = XrmServiceToolkit.Soap.Fetch(componentXml); 
      console.log("the respective component is " + fetchComponent); 
     } 
    } 
} 

日誌聲明只是爲了測試,如果我得到的信息,我需要同時檢測

日誌報表顯示我,我肯定,但我得到的產品名稱。沒有得到相應的組件。

我使用Fetch查看構建查詢,但我不認爲我正確理解它們,因爲它沒有獲取我期望的信息。很明顯,這是一個不完整的功能,但我想確保在寫出剩下的內容之前獲得所需的信息。

有什麼建議嗎?

+0

這fetch語句看起來不錯(雖然我會切換到產品編號,而不是名稱檢索)。打開Fiddler並檢查對您的獲取呼叫的響應。如果響應不是錯誤幷包含所需的信息,那麼只需確定如何正確訪問響應對象即可。如果響應是一個錯誤,那麼你知道提取有問題。 – Polshgiant

+0

原諒我的無知,但提琴手是什麼?另外,你會知道如何正確訪問對象嗎?我的代碼中的第二個日誌語句給我「各自的組件是[對象對象]」 –

回答

0

從獲取調用返回的響應對象,你必須挖掘到,像這樣:

var componentXml = [ 
    "<fetch mapping='logical'>", 
     "<entity name='product'>", 
      "<attribute name='new_component'/>", 
      "<filter>", 
       "<condition attribute = 'name' operator='eq' value='"+productName+"' />", 
      "</filter>", 
     "</entity>", 
    "</fetch>"].join(''); 
var products = XrmServiceToolkit.Soap.Fetch(componentXml); 

if (products.length > 0) { 
    if (products[0].attributes.productid != undefined) 
     console.log("the product id is", products[0].attributes.productid); 
     console.log("new_component is", products[0].attributes.new_component); 
    } 
}