Dynamics CRM 获取所选实体的属性值

Dynamics CRM get selected entity's attribute value

我需要获取在查找中选择的实体的属性值 ("val_index")。

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"
}

我该怎么做?

使用 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...
    });