To retrieve the values of a lookup field or any other field in a Silverlight page, we need to follow two steps i.e 1. Design the Silverlight application to retrieve the lookup field value. And create a web resource of type Silverlight and upload the .xap file.
2. Create a webresource in the form customization area and pass the field name whose value is needed in the silverlight page as a parameter in the “custom parameter” area and point to the web resource created in the step 1.
We are done with the basic setup.
Now lets walkthrough the codes for retrieving values in the Silverlight application as below
We need to modify the Application_startup method to captture the parameter passed from the crm controls.
Now in the Mainpage.xaml.cs we will get a hold on crm object and retrieve the value of the parameter that we have passed as below,
dynamic xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm"); var fieldName = Application.Current.Resources["InitParm_data"]; // for getting primary contact lookup field var numAttr1 = xrm.Page.data.entity.attributes.get(fieldName).getValue()[0].id;
In the same way we can retrieve different other fields.
We can also set the crm field values from within the silverlight application as below-
dynamic xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm"); var numAttr = xrm.Page.data.entity.attributes.get("ser_noofusers");//ser_noofusers is a custom field numAttr.setValue(Math.Round(slider1.Value, 0));