mardi 11 février 2014

Accessing Dynamics CRM filtered views using a SQL Server account

When writing reports or dashboards for Dynamics CRM, the filtered views are very useful. They automatically filter the data based on the application defined security without having to go through the web services.  Typically, the filtered views are the only database objects exposed to the average user in Dynamics CRM, and they are the only access method aside from web services that is officially supported. They do have a major limitation though in that only a Windows account can normally be used to access them. Using a SQL server account will result in no data being returned. There are some instances where access to the database is required, but a Windows account just isn't feasible.

There is a way to access filtered views using a SQL Server user account by taking advantage of a feature built into the filtered views. There are two steps required.

First, add the SQL Server user account, giving it access to the organization database in the CRMReaderRole role.

USE [master]
GO
CREATE LOGIN [MyUser] WITH PASSWORD=N'MyPassword'
GO
USE [ORGDB_MSCRM]
GO
CREATE USER [MyUser] FOR LOGIN [MyUser]
GO
EXEC sp_addrolemember N'CRMReaderRole', N'MyUser'
GO

Next, obtain the GUID for the Dynamics CRM user you would like to impersonate.  This can be done by querying the SystemUser table directly, or through the Dynamics CRM user interface by displaying the user's properties and examining the page URL .  Use the Transact-SQL SET CONTEXT_INFO to set the context information to this GUID before querying the filtered view.

DECLARE  @uid uniqueidentifier
SET @uid = convert(uniqueidentifier, 'user_guid_goes_here')
SET CONTEXT_INFO @uid

SELECT TOP 1000 *
  FROM [ORGDB_MSCRM].[dbo].[FilteredContact]

The query will return the records as if you were connected using the given user's Windows account.  It should be noted that the SET CONTEXT_INFO is only required when establishing the connection, and once set will remain so for the duration of the session.

Building a Windows Phone 7 CRM client

This Christmas I decided to treat myself by buying a new Windows Phone 7 (WP7).  Since I have my family on the T-Mobile network, I chose the HD7 phone from HTC.  While I find this phone a little too large to use comfortably in one hand, the large screen is great for gaming and media applications.  I have an Xbox Live family subscription, and the Xbox Live integration lets me check on what my family is doing on their Xboxes, send messages directly to the game consoles, and check on any game invites or turn notifications I might have received.  I’m patiently waiting for Fable Coin Golf to be released for WP7 so that I can earn money for my Xbox Fable III character through the phone.

While I think the iTunes application is more polished and easier to use than the Zune software, the subscription model followed by the Zune certainly makes building a large music library quickly much cheaper.  I don’t typically watch Netflix on my WP7, but I do watch a number of podcasts.  These both look and sound great through the HD7.  For this reason, I’ve replaced my iPod Touch with my WP7.  A tip for anyone using HTC phones, download the HTC Sound Enhancer application from the marketplace.   It makes a big difference in the sound quality, especially when using headphones.  Also, HTC’s YouTube browser is much better than any of the others on the marketplace.

Games and media aside, I have been pleasantly surprised at just how productive I have been on the WP7 in a very short period of time.  Through the people hub I can search my company’s Exchange global address book and can save contacts from there to one of my personal address lists.  The contact information from Outlook, Windows Live, Google and Facebook are seamlessly integrated into a single display.  I have my family contacts pinned to my start screen, and in addition to giving instant access to call or text them, I can also see any social status updates they have made right on my start screen.

The Office hub lets me open and edit any office document and post it to SharePoint if desired.  The SharePoint integration works great, although oddly enough it does not work if the server only supports Windows authentication.  Since getting the WP7, OneNote has actually became useful again.  My notes taken on the phone are automatically uploaded to my Windows Live SkyDrive.

The most notable absences in the WP7 are CRM and Office Communicator.  Microsoft has announced that the Lync (Office Communicator's successor) for WP7 is in the works, and the list of features includes messaging, VOIP calling, conference calls and seamless call transfers from the desktop to the phone.

While I’m certain that Dynamics CRM integration is also in the works, I naturally couldn’t wait.  My organization isn’t yet on CRM 2011, so I built a client against our on premise CRM 4.0 deployment.  The related code for this project can be downloaded here.  In order to get it to work, add a service reference to the CRMMobileClient project to your CRM deployment and name the service reference CrmService.




The first issue to overcome in building a CRM client was how to reference the CRM web services.  There isn’t a CRM mobile SDK yet, and the WP7 does not support the older style web service client suggested for accessing the CRM web services.  This leaves using a WCF client to access the web services as the only option.  But after adding the service reference to the Silverlight project, there are several missing attributes to the generated proxy class.  Most notably the generated service does not have a CrmAuthenticationTokenValue property.

Fortunately a lot of the research had already been done for me by Pierre-Adrien Forestier in his blog post How to consume CRM 4.0 Web Services from a WCF client like Silverlight applications.  This blog post describes how to add the CrmAuthenticationToken header to the outgoing requests using the OperationContextScope and a custom serializer class.   Since the WP7 development platform allows for Silverlight applications, this code seemed ideal.  Unfortunately as written it only works when using Windows integrated authentication.  There isn’t a way to pass Windows credentials on the WCF transport from the WP7, so using Windows authentication is not an option.  Basic authentication must be used on the CRM IIS server in order to access it from phone applications.  Using the TransportCredentialOnly security mode you can simply set the id and password on the client credentials object and with the custom serializer you will be able to access the CRM server over HTTP.

System.ServiceModel.BasicHttpBinding binding = new 
    System.ServiceModel.BasicHttpBinding(
    System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly);

 binding.Name = "CrmServiceBinding";

service.ClientCredentials.UserName.UserName = "username";
service.ClientCredentials.UserName.Password = "password";

Unfortunately, this only works over HTTP; executing this code over HTTPS will generate an error.  The next hurtle was how to use Basic authentication securely.  Using a secure connection is recommended since Basic authentication passes the id/password in clear text, but there isn’t a built in way to pass Basic authentication credentials from the WP7.  Normally you would use code similar to the following:

System.ServiceModel.BasicHttpBinding binding = new 
    System.ServiceModel.BasicHttpBinding(
    System.ServiceModel.BasicHttpSecurityMode.Transport);

 binding.Name = "CrmServiceBinding";
 binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
 binding.Security.Transport.ClientCredentialType = 
    System.ServiceModel.HttpClientCredentialType.Basic;

Unfortunately, Silverlight does not expose the Transport property of the BasicHttpSecurity object so there is no way to configure the client proxy to automatically add the Basic authentication header to your requests.  To implement Basic authentication over HTTPS you must manually add the required header to the request in a similar fashion to adding the CrmAuthenticationToken.  The following code demonstrates.
 
public void AsyncGetContact(Guid contactId)
{
    using (new OperationContextScope((IContextChannel)Service.InnerChannel))
    {
        string myCredentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(UserName + ":" + Password)); 
        // You can't configure the authentication in the transport, so the basic 
        // authentication header has to be added here.
        HttpRequestMessageProperty prop = new HttpRequestMessageProperty();
        prop.Headers["Authorization"] = "Basic " + myCredentials;
        OperationContext.Current.OutgoingMessageProperties.Add(
            HttpRequestMessageProperty.Name, prop);
        // here, we inject the CRM Authentication header 
        // The Xml formatter is just to prevent some characters from being encoded 
        // (otherwise CRM can't parse the authentication token properly)
        MessageHeader header = MessageHeader.CreateHeader("CrmAuthenticationToken", 
            "http://schemas.microsoft.com/crm/2007/WebServices", "", 
            new MyCrmAuthenticationTokenSerializer(0, Organization, null));
                
        // Insert SOAP header 
        OperationContext.Current.OutgoingMessageHeaders.Add(header);

        // Create the column set to retrieve
        ColumnSet cols = new ColumnSet();
        cols.Attributes = ContactEntity.ColumnList;

        // Create the retrieve target.
        TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();
        // Set the properties of the target.
        targetRetrieve.EntityName = EntityName.contact.ToString();
        targetRetrieve.EntityId = contactId;
        RetrieveRequest req = new RetrieveRequest();
        req.ColumnSet = cols;
        req.ReturnDynamicEntities = true;
        req.Target = targetRetrieve;
        Service.ExecuteAsync(req);
    }
}

Another item you might notice in the above code is that it uses the Execute method and DynamicEntity rather than the Retrieve method and the custom contact entity class.  For a line of business application, using the generated entity classes isn’t an issue, but I wouldn’t recommend it if you plan to distribute your application on the marketplace.

To test my client class I built a small test application.  This application simply allows you to enter the server, organization, user name, password, and the GUID of a contact you wish to retrieve from CRM.  This wouldn’t be overly useful for a LOB application, but does work to insure that the CRM system can be successfully queried.


An interesting anomaly I found when building this application is that the initial connection to the web service takes much longer than subsequent queries (from 8 to sometimes 30 seconds).  Stranger still is the fact that even though the call is asynchronous, rather than return immediately as expected, several seconds pass as the call is invoked.  After doing some research I’ve found that this is typical of WCF clients and that two reasons are usually the culprit.  The first is related to the client attempting to connect to a proxy before making the web service connection.  It’s doubtful that this would be the case on the WP7, and hopefully it isn’t as neither useDefaultWebProxy nor bypassProxyOnLocal are accessible to alter this behavior.   The second possible cause has to do with XML serialization.   According to http://msdn.microsoft.com/en-us/library/aa751883.aspx the startup speed of a WCF client can be improved by using the svcutil.exe tool to generate code to serialize the xml.  Unfortunately this tool does not work with Windows phone assemblies, but I'm confident that serialization code can be created by including the classes in a traditional .Net assembly, using the tool to generate the serializtion classes, and then adding these classes back to your WP7 project.   I have yet to attempt this experiment, but will be sure to post an update when I do.

To work around this issue in the UI, make sure that you call the service code from a different thread.  While it seems odd to call an asynchronous method from another asynchronous method, not doing so causes a noticeable delay as the service asynchronous call is launched.

While WCF and REST services are becoming quite widespread, there are still a number of applications that work using older style web services.  While some of the challenges to connecting to Dynamics CRM are unique, most of the issues are typical of connecting to web services.  I hope this blog entry gives some useful tips to anyone out there struggling to get their own connected applications to work properly.

lundi 10 février 2014

How to Display a Report in a Dashboard in Dynamics CRM 2011?

There are a lot of reasons to display a Report within a Dashboard. And i have decided to write my own blog for this purpose And take help from this blog. So today i am sharing the steps so you can do it on your project too.
1. Run the report you want to display in a Dashboard.
2. Press F11 Copy the URL that displays in address bar
3. Create a New Dashboard. Chose any layout that fits in your requirement
4. Insert an IFRAME in the Dashboard.








5.  Paste the above Url after making the following adjustments to it:
  • Remove “http://myservername/myorgname” . This will make your url relative.
  • Replace “?action=filter” with “?action=run”. This will bypass the first step before running the report where CRM asks for some parameters.
for instance, if the original url was:
http://crm-vm222/MyOrg222/crmreports/viewer/viewer.aspx?action=filter&helpID=My%20Report%20Name.rdl&id=%7bE70C6DCA-31FF-E011-807F-CCCC293AE41E%7d
..then, you should write:
/crmreports/viewer/viewer.aspx?action=run&helpID=My%20Report%20Name.rdl&id=%7bE70C6DCA-31FF-E011-807F-CCCC293AE41E%7d

6. Also, clear checkbox ‘Restrict cross-frame scripting’ . At least in my case I had to do that to make it work.



7. Use the buttons ‘Increase Width’ and ‘Increase Height’ so as to make the IFRAME fill the whole page of your Dashboard (or just the space it’s supposed to need).


8. Save & Close the Dashboard.
9. Publish the Dashboard.
10. Try It! :) . After publishing make some minor changes like size / layout depending upon your requirement.But our main pupose has been achieved which is displaying the report.

Xrm.Utility Reference Microsoft Dynamics CRM 2011

NEW XRM.UTILITY FUNCTIONS IN UPDATE ROLLUP 8 FOR MICROSOFT DYNAMICS CRM 2011 AND MICROSOFT DYNAMICS CRM ONLINE

Microsoft has introduce a new Xrm reference. These functions are available in every application page that supports script.
The functions are below
 
Function
Description
openEntityForm
Opens an entity form
openWebResource
Opens an HTML web resource.

1. openEnityForm
Use to open an entity.

Syntax
Xrm.Utility.openEntityForm(name,id,parameters)

Examples:
Open a new account record
Xrm.Utility.openEntityForm("account");
Open an existing account record
Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410");
Open a new account record with a specific form and setting default values
var parameters = {};
parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";
parameters["name"] = "Test";
parameters["telephone1"] = "(425) 555-1234";
Xrm.Utility.openEntityForm("account", null, parameters);
Open a new contact record, move it to the top left corner of the screen, and set the size of the window
Note
You cannot use window object methods such as moveTo or resizeTo in scripts that will run in Microsoft Dynamics CRM for Microsoft Office Outlook.
var newWindow = Xrm.Utility.openEntityForm("contact");
newWindow.moveTo(0,0);
newWindow.resizeTo(800,600);

2. openWebResource

Opens an HTML web resource.

Syntax
Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height)

Examples:
1.     Open an HTML web resource named “new_webResource.htm”:
Xrm.Utility.openWebResource("new_webResource.htm");
2.     Open an HTML web resource including a single item of data for the data parameter”
Xrm.Utility.openWebResource("new_webResource.htm","dataItemValue");
3.     Open an HTML web resource passing multiple values through the data parameter
var customParameters = encodeURIComponent("first=First Value&second=Second Value&third=Third Value");
Xrm.Utility.openWebResource("new_webResource.htm",customParameters);

Note
These values have to be extracted from the value of the data parameter in the HTML web resource. For more information, see Sample: Pass Multiple Values to a Web Resource Through the Data Parameter.
Open an HTML web resource with the parameters expected by HTML web resources:
Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033");
Open an HTML web resource, setting the height and width:
Xrm.Utility.openWebResource("new_webResource.htm", null, 300,300);

Calculate Mileage in CRM 2011 using Google API

Some companies are using Mileage functionality to give there employees Travel allowance. To automate this process we can use Google API to Get the distance and give allowance to there employee.
Google Map API requires two fields Origin, Destination and it gives us its complete detail i.e. Correct address, Distance etc. But for now we only need distance to give our employee Travel allowance depending upon the distance that they travels. It is really helpful in any Marketing Company or any other company that gives Travel allowance to its employees.

Prerequisites for Integration between CRM 2011 and Google Map Api

1. CRM 2011
2. Google Map API Script File (Download)

Note: This code works on Zip code. Enter the Origin, Destination and then Cost per mile.

Here is the complete code you only need to change the Bold lines (Schema Names)


 function calculateCost()  
 {  
 var distance = Xrm.Page.data.entity.attributes.get("new_distance").getValue();  
 var costpermile = Xrm.Page.data.entity.attributes.get("new_costpermile").getValue();  
 var totalCost = distance * costpermile;  
 var Name = Xrm.Page.data.entity.attributes.get("new_totalcost");   
   Name.setValue(totalCost);  
 }  

 function GetMilesFromZipcodes()  
 {  

 //Please pass your origin and destination values here.
 var origin1 = Xrm.Page.data.entity.attributes.get("new_origin").getValue();   
 var destinationA = Xrm.Page.data.entity.attributes.get("new_destination").getValue(); 
 var distance = Xrm.Page.data.entity.attributes.get("new_distance");
 var service = new google.maps.DistanceMatrixService();  
 service.getDistanceMatrix(  
  {  
   origins: [origin1],  
   destinations: [destinationA],  
   travelMode: google.maps.TravelMode.DRIVING,  
   avoidHighways: false,  
   avoidTolls: false  
  }, callback);  
 function callback(response, status) {  
 if (status == google.maps.DistanceMatrixStatus.OK) {  
   var origins = response.originAddresses;  
   var destinations = response.destinationAddresses;  
   for (var i = 0; i < origins.length; i++) {  
    var results = response.rows[i].elements;  
    for (var j = 0; j < results.length; j++) {  
     var element = results[j];  
     var distance = element.distance.value;  
     //Convert KM to Miles
     var distance1 = (distance * 0.621371)/1000;  
    
   distance.setValue(distance1);  
     var duration = element.duration.text;  
     var from = origins[i];  
     var to = destinations[j];  
    }  
   }  
  }  
 }  
 }  
 window.google = window.google || {};  
 google.maps = google.maps || {};  
 (function() {  
  function getScript(src) {  
   document.write('<' + 'script src="' + src + '"' +  
           ' type="text/javascript"><' + '/script>');  
  }  
  var modules = google.maps.modules = {};  
  google.maps.__gjsload__ = function(name, text) {  
   modules[name] = text;  
  };  
  google.maps.Load = function(apiLoad) {  
   delete google.maps.Load;  
   apiLoad([0.009999999776482582,[[["https://mts0.googleapis.com/vt?lyrs=m@199000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=m@199000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"m@199000000"],[["https://khms0.googleapis.com/kh?v=121\u0026hl=en-US\u0026","https://khms1.googleapis.com/kh?v=121\u0026hl=en-US\u0026"],null,null,null,1,"121"],[["https://mts0.googleapis.com/vt?lyrs=h@199000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=h@199000000\u0026src=api\u0026hl=en-US\u0026"],null,null,"imgtp=png32\u0026",null,"h@199000000"],[["https://mts0.googleapis.com/vt?lyrs=t@129,r@199000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=t@129,r@199000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"t@129,r@199000000"],null,[[null,0,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1314843700]]],["https://mt0.gmaptiles.co.kr/mt?v=kr1.17\u0026hl=en-US\u0026","https://mt1.gmaptiles.co.kr/mt?v=kr1.17\u0026hl=en-US\u0026"]],[null,0,8,8,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[354690000,1286700000],[386200000,1314843700]]],["https://mt0.gmaptiles.co.kr/mt?v=kr1.17\u0026hl=en-US\u0026","https://mt1.gmaptiles.co.kr/mt?v=kr1.17\u0026hl=en-US\u0026"]],[null,0,9,9,[[[330000000,1246050000],[386200000,1279600000]],[[340000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1302000000]],[[368300000,1302000000],[386200000,1314843700]]],["https://mt0.gmaptiles.co.kr/mt?v=kr1.17\u0026hl=en-US\u0026","https://mt1.gmaptiles.co.kr/mt?v=kr1.17\u0026hl=en-US\u0026"]],[null,0,10,19,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1314843700]]],["https://mt0.gmaptiles.co.kr/mt?v=kr1.17\u0026hl=en-US\u0026","https://mt1.gmaptiles.co.kr/mt?v=kr1.17\u0026hl=en-US\u0026"]],[null,3,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1314843700]]],["https://mt0.gmaptiles.co.kr/mt?v=kr1p.17\u0026hl=en-US\u0026","https://mt1.gmaptiles.co.kr/mt?v=kr1p.17\u0026hl=en-US\u0026"]],[null,3,8,8,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[354690000,1286700000],[386200000,1314843700]]],["https://mt0.gmaptiles.co.kr/mt?v=kr1p.17\u0026hl=en-US\u0026","https://mt1.gmaptiles.co.kr/mt?v=kr1p.17\u0026hl=en-US\u0026"]],[null,3,9,9,[[[330000000,1246050000],[386200000,1279600000]],[[340000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1302000000]],[[368300000,1302000000],[386200000,1314843700]]],["https://mt0.gmaptiles.co.kr/mt?v=kr1p.17\u0026hl=en-US\u0026","https://mt1.gmaptiles.co.kr/mt?v=kr1p.17\u0026hl=en-US\u0026"]],[null,3,10,null,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1314843700]]],["https://mt0.gmaptiles.co.kr/mt?v=kr1p.17\u0026hl=en-US\u0026","https://mt1.gmaptiles.co.kr/mt?v=kr1p.17\u0026hl=en-US\u0026"]]],[["https://cbks0.googleapis.com/cbk?","https://cbks1.googleapis.com/cbk?"]],[["https://khms0.googleapis.com/kh?v=66\u0026hl=en-US\u0026","https://khms1.googleapis.com/kh?v=66\u0026hl=en-US\u0026"],null,null,null,null,"66"],[["https://mts0.googleapis.com/mapslt?hl=en-US\u0026","https://mts1.googleapis.com/mapslt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/ft?hl=en-US\u0026"]],[["https://mts0.googleapis.com/vt?hl=en-US\u0026","https://mts1.googleapis.com/vt?hl=en-US\u0026"]]],["en-US","US",null,0,null,null,"https://maps.gstatic.com/mapfiles/","https://csi.gstatic.com","https://maps.googleapis.com","https://maps.googleapis.com"],["https://maps.gstatic.com/intl/en_us/mapfiles/api-3/11/0","3.11.0"],[3613555064],1.0,null,null,null,null,0,"",null,null,1,"https://khms.googleapis.com/mz?v=121\u0026",null,"https://earthbuilder.google.com","https://earthbuilder.googleapis.com"], loadScriptTime);  
  };  
  var loadScriptTime = (new Date).getTime();  
  getScript("https://maps.gstatic.com/intl/en_us/mapfiles/api-3/11/0/main.js");  
 })();  

Screen Shot

How to manage queues in CRM 2011


HOW TO MANAGE QUEUES IN CRM 2011


Microsoft CRM 2011 has a great option of queues and using queues we could assign any custom entity to queues. Not only custom entities but also built-in entities like lead activities cases etc.
In any organization if any user has to interact with multiple entities at the same time then we can use queue feature to organizing items more effectively.
For example in my last project we have to handle admission system. For this purpose we have used queues.
 
The process for application submission is as follow

1.   Any receptionist will receive the application and submit it to admission office for further process.

2. Receptionist receives a call from anywhere and his responsibility is to generate lead.
Receptionist gets interact with two entities.
1. Admission form 
2. Lead
 
If enrolled person get qualified admission department send him a letter and when student submit his fee admission department will enrolled the student.
In the above scenario multiple users has to work on a same entity.


ENABLING QUEUES FOR LEAD (BUILT-IN ENTITIES)

 


Check the Queues box. And if you want to automatically move records to the owner’s default queue when record is created check the other check box too.
Note: Once queues enabled we cannot reverse it status. 

ENABLING QUEUES FOR CUSTOM ENTITIES


As we discuss above we could unable queues for custom entities to.


Check the queues check box and save the entity now queues is enabled on employee entity.

DEFAULT QUEUES

Default queues are automatically generated for user’s teams and business units. All of these can also be used for managing user rights. Here is a list of default queues items
  1. Activity
  2. Appointment
  3. Campaign
  4. Activity
  5. Campaign response
  6. Case
  7. Email
  8. Fax
  9. Lead
  10. Letter
  11. Phone call
  12. Quick campaign
  13. Recurring appointment
  14. Service Activity
  15. Task
  16. User
  17. Team

SETTINGS VIEWS FOR QUEUES


We could set views for the queues to make our work easier.
Currently I want to see only leads that are assigned to me or I am the owner of the lead.
1. Go to Queues item and click on New.
 2. Give the Name of the view (Leads) I am working On
 2. Click on Edit Filter Criteria.
 3. Give your criteria as below
 4. Select your columns and click on Save and Close
 5. Now you can see the View (Leads) I am working On and all the leads that required some action.

Add Multiple Entities (Members) to a Marketing List in Microsoft Dynamics CRM 2011 Using .NET or Jscript

This illustration shows how to add a list of entities (members) to a marketing list in Microsoft Dynamics CRM 2011 with AddListMembersListRequest. This example will be given in Jscript (SOAP) and in C# (.NET).

Note: The entity type you add to your marketing list must be consistent with the entity type for the list and must be either an account, contact, or a lead.
Ok, here is what the code looks like!
First in C#:

AddListMembersListRequest req = new AddListMembersListRequest();
req.ListId = new Guid("6CAC04FC-930F-E111-8DB2-1CC1DEF1B5FF");
//add the new list of marketing list memnbers
req.MemberIds = new System.Guid[2];
req.MemberIds[0] = new Guid("DCB265C9-5F0C-E111-BF0B-1CC1DEE89AA8");
req.MemberIds[1] = new Guid("E4B265C9-5F0C-E111-BF0B-1CC1DEE89AA8");
AddListMembersListResponse resp = (AddListMembersListResponse)service.Execute(req);


Now here is the Jscript nicely formatted by the CRM 2011 SOAP formatter. Available at:http://crm2011soap.codeplex.com/

Now in Jscript


if (typeof (SDK) == "undefined")    { SDK = { __namespace: true }; }        //This will establish a more unique namespace for functions in this library. This will reduce the         // potential for functions to be overwritten due to a duplicate name when the library is loaded.        SDK.SAMPLES = {            _getServerUrl: function () {                ///                /// Returns the URL for the SOAP endpoint using the context information available in the form                /// or HTML Web resource.                ///                var OrgServicePath = "/XRMServices/2011/Organization.svc/web";                var serverUrl = "";                if (typeof GetGlobalContext == "function") {                    var context = GetGlobalContext();                    serverUrl = context.getServerUrl();                }                else {                    if (typeof Xrm.Page.context == "object") {                          serverUrl = Xrm.Page.context.getServerUrl();                    }                    else                    { throw new Error("Unable to access the server URL"); }                    }                   if (serverUrl.match(/\/$/)) {                        serverUrl = serverUrl.substring(0, serverUrl.length - 1);                    }                     return serverUrl + OrgServicePath;                },             AddListMembersListRequest: function () {                var requestMain = ""                requestMain += "";                requestMain += "  ";                requestMain += "    ";                requestMain += "      ";                requestMain += "        ";                requestMain += "          ";                requestMain += "            ListId";                requestMain += "            6cac04fc-930f-e111-8db2-1cc1def1b5ff";                requestMain += "          ";                requestMain += "          ";                requestMain += "            MemberIds";                requestMain += "            ";                requestMain += "              dcb265c9-5f0c-e111-bf0b-1cc1dee89aa8";                requestMain += "              e4b265c9-5f0c-e111-bf0b-1cc1dee89aa8";                requestMain += "            ";                requestMain += "          ";                requestMain += "        ";                requestMain += "        ";                requestMain += "        AddListMembersList";                requestMain += "      ";                requestMain += "    ";                requestMain += "  ";                requestMain += "";                var req = new XMLHttpRequest();                req.open("POST", SDK.SAMPLES._getServerUrl(), true)                // Responses will return XML. It isn't possible to return JSON.                req.setRequestHeader("Accept", "application/xml, text/xml, */*");                req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");                req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");                var successCallback = null;                var errorCallback = null;                req.onreadystatechange = function () { SDK.SAMPLES.AddListMembersListResponse(req, successCallback, errorCallback); };                req.send(requestMain);            },        AddListMembersListResponse: function (req, successCallback, errorCallback) {                ///                /// Recieves the assign response                ///                ///                /// The XMLHttpRequest response                ///                ///                /// The function to perform when an successfult response is returned.                /// For this message no data is returned so a success callback is not really necessary.                ///                ///                /// The function to perform when an error is returned.                /// This function accepts a JScript error returned by the _getError function                ///                if (req.readyState == 4) {                if (req.status == 200) {                if (successCallback != null)                { successCallback(); }                }                else {                    errorCallback(SDK.SAMPLES._getError(req.responseXML));                }            }        },        _getError: function (faultXml) {            ///            /// Parses the WCF fault returned in the event of an error.            ///            ///            /// The responseXML property of the XMLHttpRequest response.            ///            var errorMessage = "Unknown Error (Unable to parse the fault)";            if (typeof faultXml == "object") {                try {                    var bodyNode = faultXml.firstChild.firstChild;                    //Retrieve the fault node                    for (var i = 0; i < bodyNode.childNodes.length; i++) {                        var node = bodyNode.childNodes[i];                        //NOTE: This comparison does not handle the case where the XML namespace changes                        if ("s:Fault" == node.nodeName) {                        for (var j = 0; j < node.childNodes.length; j++) {                            var faultStringNode = node.childNodes[j];                            if ("faultstring" == faultStringNode.nodeName) {                                errorMessage = faultStringNode.text;                                break;                            }                        }                        break;                    }                }            }            catch (e) { };         }         return new Error(errorMessage);      },  __namespace: true };