In CRM2011, Silverlight Web resources can be debugged in Microsoft Visual Studio. For this you need to follow below steps:
• Build your Silverlight application.
• Upload the built version of the .xap file from the Web application project ClientBin folder.
• View your Silverlight application in the context it is designed to be used in.
• In your Silverlight application project, from the Visual Studio menu, select Debug and then Attach To Process….
• In the Attach to Process dialog box, find an iexplore.exe process where the Type column value is Silverlight, x86. (See below screen shot)
• Select that process and press Attach to close the dialog box and start debugging.
• In your Silverlight application project, set a breakpoint.
• Refresh the browser window or, in the Silverlight application, perform the action that you need to test your code.
Hope this help
Tuesday, September 13, 2011
How to interact with CRM form fields from within the Silverlight page
At times you may have a need to interact with the CRM form to read/update back the latest information after the processing completes from a custom application.
Say we add a button on the Entity form and when user will click on this button then we can read as well as set the value of the entity form fields. Below we have given the example to read the activityparty.
When you click on the button then it will open a child window. To access the CRM form we will need to use the Parent window from which this child window was called. Here we are reading the values of the Sender attribute of the Email.
dynamic win = HtmlPage.Window;
dynamic opener = win.parent.opener;
ScriptObject xrm = (ScriptObject)opener.GetProperty("Xrm");
ScriptObject page = (ScriptObject)xrm.GetProperty("Page");
dynamic dynamicPage = page;
dynamic lookupItems = dynamicPage.data.entity.attributes.get("to").getValue();
HtmlPage.Window.Invoke("readLookup", lookupItems);
“To” attribute is of the type lookup and it will be an array of objects. To read the values for this lookup you need to write the following script on the html page.
function readLookup(source) {
if (source == null) {
return;
}
var array = new Array();
array = source;
for (i = 0; i < array.length; i++) {
alert(array[i].entityType);
alert(array[i].id);
alert(array[i].name);
}
}
Now say you want to update the Subject of the Email from within the Silverlight custom application, you can refer the CRM form and update the controls on the form as shown below
dynamicPage.data.entity.attributes.get("subject").setValue("Test 1234");
Since Subject is a text field it could be done as simply as above.
But to set the value for the lookup and date type of attributes, there is still more to be done. For this we need to add a java script web resource on the required entity. This web resource will contain the function to set the lookup and the date value. We then need to call this function from the Silverlight page. Code below explains how this can be done
dynamic parent = win.parent.opener;
parent.setLookupValue();
he SetLookupValue will contain the code to set the value for the lookup. As given below.
Xrm.Page.data.entity.attributes.get("regardingobjectid").setValue(array);
Hope this helps in designing richer Silverlight applications that interact better with the CRM forms.
Say we add a button on the Entity form and when user will click on this button then we can read as well as set the value of the entity form fields. Below we have given the example to read the activityparty.
When you click on the button then it will open a child window. To access the CRM form we will need to use the Parent window from which this child window was called. Here we are reading the values of the Sender attribute of the Email.
dynamic win = HtmlPage.Window;
dynamic opener = win.parent.opener;
ScriptObject xrm = (ScriptObject)opener.GetProperty("Xrm");
ScriptObject page = (ScriptObject)xrm.GetProperty("Page");
dynamic dynamicPage = page;
dynamic lookupItems = dynamicPage.data.entity.attributes.get("to").getValue();
HtmlPage.Window.Invoke("readLookup", lookupItems);
“To” attribute is of the type lookup and it will be an array of objects. To read the values for this lookup you need to write the following script on the html page.
function readLookup(source) {
if (source == null) {
return;
}
var array = new Array();
array = source;
for (i = 0; i < array.length; i++) {
alert(array[i].entityType);
alert(array[i].id);
alert(array[i].name);
}
}
Now say you want to update the Subject of the Email from within the Silverlight custom application, you can refer the CRM form and update the controls on the form as shown below
dynamicPage.data.entity.attributes.get("subject").setValue("Test 1234");
Since Subject is a text field it could be done as simply as above.
But to set the value for the lookup and date type of attributes, there is still more to be done. For this we need to add a java script web resource on the required entity. This web resource will contain the function to set the lookup and the date value. We then need to call this function from the Silverlight page. Code below explains how this can be done
dynamic parent = win.parent.opener;
parent.setLookupValue();
he SetLookupValue will contain the code to set the value for the lookup. As given below.
Xrm.Page.data.entity.attributes.get("regardingobjectid").setValue(array);
Hope this helps in designing richer Silverlight applications that interact better with the CRM forms.
Tuesday, September 6, 2011
Retrieve related entity records along wih the Primary entity using Retrieve Method
We have always known the Retrieve request to be able to retrieve the data of the requested entity based on the id provided. However in CRM 2011, the Retrieve request can read not only the properties of the primary entity but also the referenced entity like in a 1-N or N-N or N-1 relationship. Given that it supports all the three types of relationships it could be an advantage over the LinkEntity feature.
For example, if we want to retrieve the active contacts related to an account then, we can design the query as shown in the below code,
using (OrganizationServiceProxy _orgserviceproxy = new OrganizationServiceProxy(new Uri(OrganizationUri), null, Credentials, null))
{
//create the query expression object
QueryExpression query = new QueryExpression();
//Query on reated entity records
query.EntityName = "contact";
//Retrieve the all attributes of the related record
query.ColumnSet = new ColumnSet(true);
//create the relationship object
Relationship relationship = new Relationship();
//add the condition where you can retrieve only the account related active contacts
query.Criteria = new FilterExpression();
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, "Active"));
// name of relationship between account & contact
relationship.SchemaName = "contact_customer_accounts";
//create relationshipQueryCollection Object
RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection();
//Add the your relation and query to the RelationshipQueryCollection
relatedEntity.Add(relationship, query);
//create the retrieve request object
RetrieveRequest request = new RetrieveRequest();
//add the relatedentities query
request.RelatedEntitiesQuery = relatedEntity;
//set column to and the condition for the account
request.ColumnSet = new ColumnSet("accountid");
request.Target = new EntityReference { Id = accountID, LogicalName = "account" };
//execute the request
RetrieveResponse response = (RetrieveResponse)_orgserviceproxy.Execute(request);
// here you can check collection count
if (((DataCollection)(((RelatedEntityCollection)(response.Entity.RelatedEntities)))).Contains(new Relationship("contact_customer_accounts")) &&((DataCollection)(((RelatedEntityCollection)(response.Entity.RelatedEntities))))[new Relationship("contact_customer_accounts")].Entities.Count > 0)
return true;
else
return false;
}
One limitation though, is that it is only available with the Retrieve Request and not the Retrieve Multiple request. Wonder why this has not be added for Retrieve Multiple request as this can be of great help to return all the data required in one request.
For example, if we want to retrieve the active contacts related to an account then, we can design the query as shown in the below code,
using (OrganizationServiceProxy _orgserviceproxy = new OrganizationServiceProxy(new Uri(OrganizationUri), null, Credentials, null))
{
//create the query expression object
QueryExpression query = new QueryExpression();
//Query on reated entity records
query.EntityName = "contact";
//Retrieve the all attributes of the related record
query.ColumnSet = new ColumnSet(true);
//create the relationship object
Relationship relationship = new Relationship();
//add the condition where you can retrieve only the account related active contacts
query.Criteria = new FilterExpression();
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, "Active"));
// name of relationship between account & contact
relationship.SchemaName = "contact_customer_accounts";
//create relationshipQueryCollection Object
RelationshipQueryCollection relatedEntity = new RelationshipQueryCollection();
//Add the your relation and query to the RelationshipQueryCollection
relatedEntity.Add(relationship, query);
//create the retrieve request object
RetrieveRequest request = new RetrieveRequest();
//add the relatedentities query
request.RelatedEntitiesQuery = relatedEntity;
//set column to and the condition for the account
request.ColumnSet = new ColumnSet("accountid");
request.Target = new EntityReference { Id = accountID, LogicalName = "account" };
//execute the request
RetrieveResponse response = (RetrieveResponse)_orgserviceproxy.Execute(request);
// here you can check collection count
if (((DataCollection
return true;
else
return false;
}
One limitation though, is that it is only available with the Retrieve Request and not the Retrieve Multiple request. Wonder why this has not be added for Retrieve Multiple request as this can be of great help to return all the data required in one request.
Subscribe to:
Posts (Atom)