2016-04-22 84 views
0

我需要獲取在查找中選中的實體的屬性值(「val_index」)。Dynamics CRM獲取所選實體的屬性值

function onLookupChange(){ 
    var entityName, entityId, entityLabel, lookupFieldObject; 

    lookupFieldObject = Xrm.Page.data.entity.attributes.get('my_attribute'); 
    if (lookupFieldObject.getValue() != null) { 
     entityId = lookupFieldObject.getValue()[0].id; 
     entityName = lookupFieldObject.getValue()[0].entityType; 
     entityLabel = lookupFieldObject.getValue()[0].name; 
    } 
    // here I need to get an attribute value of a selected entity. Attribute's name is "val_index" 
} 

我該怎麼做?

+1

您需要查詢的數據。 OData是Dynamics CRM 2011 - 2015的首選方法。在Dynamics CRM 2016中,您可以使用Web API界面。 –

回答

1

使用CRM SDK附帶的SDK.REST.js庫來執行此操作。將它作爲腳本包含在您的表單實體中,您可以引用這些函數來進行REST調用。

的示例調用可能是這樣的:

// Assume we are working with the account entity. 
// This call is asynchronous. 
SDK.REST.retrieveRecord(entityId, "Account", "val_index", null, 
    // Success. 
    function (result) { 
     var value = result.val_index; 
     // Do something. 
    }, 
    // Error retrieving the value. 
    function (error) { 
     // Notify the user... 
    }); 
相關問題