Reputation: 549
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);
}
}
Upvotes: 0
Views: 1639
Reputation: 15128
Type
is a lookup, so you need to access its name
property
var weighting = type[0].name.substring(4) + "-" + region;
Upvotes: 2