简体   繁体   中英

CRM 2011 Get attributes from an entity using JavaScript

I am trying to fill a read-only field automatically using a Java Script Web Resource. Now the field is dependant on a lookup containing a custom entity and a free text field of 4 characters (First part of a Postcode for Example: NW10)

I have written some JavaScript to get the values and create the new value to set in the read-only field. However when I run it the string displayed shows "[object-Object]-NW10".

I Guess what I'm asking is how do I access the attributes of the type object I passed into my function? My JavaScript is below:

function TypeAffectedOrRegionAffected_OnChanged(ExecutionContext, Type, Region, Weighting) {

var type = Xrm.Page.data.entity.attributes.get(Type).getValue();
var region = Xrm.Page.data.entity.attributes.get(Region).getValue();

// if we have values for both fields
if (type != null && region != null) {

    // create the weighting variable
    var weighting = type.substring(4) + "-" + region;

    // recreate the Weighting Value
    Xrm.Page.data.entity.attributes.get(Weighting).setValue(weighting);
}
}

Type是查找,因此您需要访问其name属性

var weighting = type[0].name.substring(4) + "-" + region;

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