Question

As the question suggests, I need to find out how to access entity data that has been passed into a JavaScript function via a lookup.

JavaScript Code Follows:

// function to generate the correct Weighting Value when these parameters change
function TypeAffectedOrRegionAffected_OnChanged(ExecutionContext, Type, Region, Weighting, Potential) {

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[0].name.substring(4) + "-" + region;

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

}

As you can see with the following line using the name operator I can access my Type entity's Type field.

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

I am looking for a way now to access the values stored inside my type object. It has the following fields new_type, new_description, new_value and new_kind.

I guess I'm looking for something like this:

// use value of entity to assign to our form field
Xrm.Page.data.entity.attributes.get(Potential).setValue(type[0].getAttribute("new_value"));

Thanks in advance for any help.

Regards,

Comic

Was it helpful?

Solution

REST OData calls are definitely the way to go in this case. You already have the id, and you just need to retrieve some additional values. Here is a sample to get you started. The hardest part with working with Odata IMHO is creating the Request Url's. There are a couple tools, that you can find on codeplex, but my favorite, is actually to use LinqPad. Just connect to your Org Odata URL, and it'll retrieve all of your entities and allow you to write a LINQ statement that will generate the URL for you, which you can test right in the browser.

For your instance, it'll look something like this (it is case sensitive, so double check that if it doesn't work):

"OdataRestURL/TypeSet(guid'" + type[0].Id.replace(/{/gi, "").replace(/}/gi, "") + "'select=new_type,new_description,new_value,new_kind"

Replace OdataRestURL with whatever your odata rest endpoint is, and you should be all set.

OTHER TIPS

Yes Guido Preite is right. You need to retrieve the entity by the id which come form the lookup by Rest Sync or Async. And then get Json object. However for make the object light which is returned, you can mention which fields to be backed as part of the Json. Now you can access those fields which you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top