我需要获取在查找中选择的实体的属性值(“ 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...
    });

09-12 20:40