Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Tuesday, July 30, 2013

How to pass Object or collection of Objects to a web resource in CRM 2011


In Dynamics CRM if we want to pass data to a web resource, then we use Xrm.Utility.openWebResource function and pass as second parameter. But in this case we can’t pass Object or Array as parameter.
 
So to solve this problem one can use JSON. Using JSON we can convert Object or Collection of Object (Array) in string format. This converted data can be used to pass data to web resource. Let us take an example of passing collection of object to web resource. Here I have used collection of array that contains Id, Description and Name of Record. 

   var arrayObject = new Array();
              arrayObject[0] = new Object();
              arrayObject[0].name = "Sample Record 1";
              arrayObject[0].id = “1.";
              arrayObject[0].decription = "Test Description ";


Then after defining collection of object we will pass that object to JSON.stringify. This function will return collection in JSON String format. Then this JSON string is encoded to get parameter that is going to passed to the web resource.

var customParameters = encodeURIComponent(JSON.stringify(arrayObject));

This encoded JSON string can be passed to web resource using below code: 

Xrm.Utility.openWebResource("new_/Records.html", customParameters);

Here “Records.html” is used for displaying this collection of object on HTML page. In web resource “Records.html”, passed parameter can be collected as follows:

var queryParam = Xrm.Page.context.getQueryStringParameters();

The collected parameter is in JSON string format so we have to convert array using JSON.parse to convert it into collection of object.

if (queryParam.Data) {
                        arrayObject = JSON.parse(queryParam.Data);
                       }


In this way we can pass collection of object as parameter to web resource. Similarly we can do for object as well. 

We have used above code for passing some data to HTML web resource Records.html. This web resource takes collection of objects. And then show in table format as you can see in below screen shot.




But when we pass parameter to web resource it is passed as query string. Query string has limitation based on browsers used. So when we pass parameter to web resource it trims/neglects extra characters from the query string. So it will cause problem while converting JSON string object into Object. And this problem of query string limitation can be solved using window.opener

The opener property returns a reference to the window that created the window. When opening a window with window.open(), you can use this property from the destination window to return details of the source (parent) window. By using window.opener we can access global parameters defined in parent web resource. In this way we can access Objects or collection without any limitations.
Let us take same example of passing collection of object to web resource. We will take collection of object defined as follows. 

               var _arrayObject = new Array();
              arrayObject[0] = new Object();
              arrayObject[0].name = "Record 1";
              arrayObject[0].id = "1.";
              arrayObject[0].decription = "Test Description";
              arrayObject[0] = new Object();
              arrayObject[0].name = "Record 2";
              arrayObject[0].id = "2.";
              arrayObject[0].decription = "Test Description";


Then we open web resource i.e. Records.html using Xrm.Utility.openWebResource.

Xrm.Utility.openWebResource("new_/Records.html");

In web resource, passed data can be collected as follows:

if (window.opener._arrayObject != null) {
                           var  _arrayObject = window.opener._arrayObject
                        }

By using above we can pass large amount of data to HTML web resource.
I have used the windows.opener to collect the data from _arrayObject global object. This collection is converted into HTML table format. I have used this code for displaying selected records into grid.



Wednesday, November 3, 2010

Displaying CRM emails using SSRS 2008

Email body in Dynamics CRM is stored in HTML format and when we try to display the data as is in the SRS report, it shows up with all the HTML tags.
Microsoft Dynamics CRM reports strip the HTML content and display it in Plain text format.
Now with SSRS 2008, you can display them with part of the HTML formatting. It does not support all the HTML tags as yet, but some basic tags are supported that help provide a presentable view of the email body.

Let’s take an example, we will create sample email as shown below.


To show same content in SSRS report 2008 we need to follow the below steps:

  1. Place a textbox control on report and within it place the PlaceHolder by right clicking inside textbox and choose PlaceHolder.

  2. Set the properties of the 'PlaceHolder', change Markup type to HTML.

  3. Extract description(body) of email by query eg. Select description from filteredemail where activityid='A0773451-3DE3-DF11-9EAB-0003FFD4167C'

  4. Set the expression value of the placeholder to description, from dataset fields.( For e.g. Fields!description.Value).

  5. Review the report to see the following result.



Hope this helps...Time to move on to SSRS 2008!