简体   繁体   中英

Dynamics CRM get selected entity's attribute value

I need to get an attribute value ("val_index") of an entity which is selected in lookup.

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

How can I do that?

Use the SDK.REST.js library which ships with the CRM SDK to do this. Include this as a script in your form entity and you can reference the functions to make REST calls.

An example call might look like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM