Wednesday, May 30, 2012

Pass parameters to web page from customization

When you want to open a web page from a cutom button in CRM 2011, there are options so that you can send parameters to the web page.

To do this follow the steps:

1) Open the customizations.xml exported from the solution
2) Find the associated <CommandDefinition> of the button in <RibbonDiffXml>/<CommandDefinitions>
3)Insert the Action statement like this:

<Actions>
<Url Address="$webresource:new_/Test.html" PassParams="true" WinParams="height=400, width=500,toolbar=no, menubar=no,location=no"> 
 </Url>
   </Actions>

Tuesday, May 29, 2012

Filter lookup programmatically using javascript on CRM form

To filter the view behind a lookup so this it will retrieve only some of the elements based on a filter it can be done follwing the steps:

1)Set the id Guid of the View, it can be a random Guid.
 var viewId = "{10109D21-27F7-4828-B131-1B5E972C4718}"; //Any Guid is fine.

2)Set the entity name to be filtered
var entityName = "new_test";// Entity to be filtered

3)Set the name for the custom view
var viewDisplayName = "Test View"; // Custom name for the lookup window

4)Create  the query that you want to retrieve. You can use  Advanced Search to make it more quickly, or you can build it yourself .

var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXML += "<entity name='new_test'>";
fetchXML += "<attribute name='new_name'/>";
 fetchXML += "<attribute name='new_code' />";
 fetchXML += "<filter type='and'>";
fetchXML += "<condition attribute='new_name' operator='like' value='%abc%'/>";

fetchXML += "</filter>";

fetchXML += "</entity>";
fetchXML += "</fetch>";

 5)Create the layout which will be displayed in the lookup


var layoutXML = "<grid name='resultset' object='1' jump='new_primary' select='1' icon='1' preview='1'>";
layoutXML += "<row name='result' id='new_name'>";
layoutXML += "<cell name='new_code' width='150' />";
layoutXML += "</row>";
layoutXML += "</grid>";

6) Assign the  custom view to the desired control:
Xrm.Page.getControl("new_testControl").addCustomView(viewId, entityName, viewDisplayName, fetchXML , layoutXML, true);

The full script is: 

 var viewId = "{10109D21-27F7-4828-B131-1B5E972C4718}"; //Any Guid is fine.
var entityName = "new_test";// Entity to be filtered
var viewDisplayName = "Test View"; // Custom name for the lookup window
var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
fetchXML += "<entity name='new_test'>";
fetchXML += "<attribute name='new_name'/>";
 fetchXML += "<attribute name='new_code' />";
 fetchXML += "<filter type='and'>";
fetchXML += "<condition attribute='new_name' operator='like' value='%abc%'/>";

fetchXML += "</filter>";

fetchXML += "</entity>";
fetchXML += "</fetch>";

var layoutXML = "<grid name='resultset' object='1' jump='new_primary' select='1' icon='1' preview='1'>";
layoutXML += "<row name='result' id='new_name'>";
layoutXML += "<cell name='new_code' width='150' />";
layoutXML += "</row>";
layoutXML += "</grid>";

 Xrm.Page.getControl("new_testControl").addCustomView(viewId, entityName, viewDisplayName, fetchXML , layoutXML, true);