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

时间:2016-04-22 08:03:45

标签: javascript dynamics-crm

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

我该怎么做?

1 个答案:

答案 0 :(得分: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...
    });