Inogic is a hub of like minded professionals who believe that innovativeness is the key for providing the most optimum solutions in the SME segment.We are committed to putting our time and efforts to Research and Develop on Dynamics CRM so that you can be benefited by the cutting edge methodologies. We endeavor to share some of our work on this blog by introducing Tips, Tricks and products from our labs.
While using CRM there may be conditions in which user wants to open forms and reports programmatically. For this we can write the scripts which will open the forms and reports.
Open CRM forms using script:
The form can be open using openEntityForm(); method.
Syntax : Xrm.Utility.openEntityForm(name,id,parameter);
Parameters :
Example:
Xrm.Utility.openEntityForm("contact");
Xrm.Utility.openEntityForm("contact","A85C0252-DF8B-E111-997C-00155D8A8410";);
function OpenNewContact() {
var parameters = {};
//Set the first name of contact to "Scott"
parameters["firstname"] = "Scott";
//Set text in the Description field.
parameters["description"] = "Description for this record";
//Set the Parent Customer field value to "John".
parameters["parentcustomerid"] = "2E862A5A-7D0F-E211-8090-00155D000501";
parameters["parentcustomeridname"] = " John ";
parameters["parentcustomeridtype"] = "account";
//Set Do not allow phone to "Do Not Allow".
parameters["donotphone"] = "1";
// Open the window.
Xrm.Utility.openEntityForm("contact", null, parameters);
}
Open Report using script:
We can also run the report using script. We just have to pass the url to window.open(); method. Below example shows how to open the report.
Syntax : window.open(url);
url need the following parameters:
action: Two possible values for this parameter are run or filter.
helped:(optional) The value should correspond to the report FileName attribute value.
Id :This parameter is the report ReportId attribute value.
function OpenReport() {
try {
//call function which will return encoded url
var url=getReportURL(filter,AllContacts,'35F560E6-1606-E211-A8FC-00155D000501');
window.open(url);
catch(e){
alert("OpenReport Error >> "+e.description);
//function to create and encode url
function getReportURL(action,fileName,id) {
var orgUrl = Xrm.Page.context.getClientUrl();
var reportUrl = orgUrl +
"/crmreports/viewer/viewer.aspx?action=" +
encodeURIComponent(action) +
"&helpID=" +
encodeURIComponent(fileName) +
"&id=%7b" +
encodeURIComponent(id) +
"%7d";
return reportUrl;
-------------------------------------------------
Posted by: Inogic
For more information/discussions (documents, sample code snippets, detailed work flow or diagrams)
Please be free to visit the following links or email us:
Web: http://www.inogic.com
Blog: http://inogic.blogspot.com
Email: news@inogic.com
--------------------------------------------------