Friday, July 15, 2011

CRM 2011 - Caller is not an owner for SubscriptionID Error

Over the past few weeks my team has been working on reviewing and revising our CRM environment in preparation to migrate to CRM 2011. As part of the preparation we have been testing the offline client and in doing so one of my devs ran into the error message of "Caller 2222222-2222-2222-2222-22222222 is not an owner for SubscriptionID 00000000-0000-0000-0000-000000000000" when attempting to go offline.


Now this odd as my devs CallerId\SystemUserId was 11111111-1111-1111-1111-111111111111 and not 2222222-2222-2222-2222-22222222, which is the SystemUserId for our TestUser1. So why was the outlook client making a call as another user? Well I after doing some initial investigation I conclude that it would just be faster to reconfigured the Outlook client, so we started the configuration wizard and typed in our server URL and hit the ‘Test Connection …’ button.  However, when it finished it showed that my dev authenticated as DOMAIN\TestUser1.


What! How is this happening? So I ask my dev, "Are you logged in as DOMAIN\TestUser1?" To which he replies, "No."  Okay, so how was the Outlook client getting another user’s credentials when it authenticates against the CRM server. Well it turned out that my dev had told IE to store the user name and password for Domain\TestUser1 when he was testing the CRM 2011 web client. We found this by going to Control Panel > User Accounts


And then clicking the ‘Manage Passwords’ button on the Advanced tab, which displays after clicking ‘User Account’


Clicking the ‘Manage Passwords’ button displays a form that lists sites that have user name and passwords saved.


When I clicked on the entry for crm.domain.com I saw the following


So to remove the entry we just selected the row for crm.domain.com and clicked the ‘Remove’ button. Once this was done we were able to reconfigure the CRM Outlook client and have it authenticate as my dev.  He wa then was able to go offline with the CRM 2011 Outlook client.

Friday, July 8, 2011

Decreasing 401 Responses

Did you know that Microsoft's CRM services team has a blog that has a wealth of information about CRM performance and other odds and ends? Hopefully you did and you saw their post titled How to Decrease 401 Responses in CRM Web Traffic. I read through it and applied their suggestions and my IIS logs now reflect about a 35% reduction in requests. That is huge considering that my user base is global and traffic is at a premium on our network. I recommend you check out the Dynamics CRM in the Field blog at https://community.dynamics.com/product/crm/crmtechnical/b/crminthefield/default.aspx and also take a look at their How to Decrease 401 Responses in CRM Web Traffic post.

Saturday, July 2, 2011

CRM 2011 - Adding scrollbars to a sub-grid

The sub-grid control in CRM 2011 is fantastic and it has replaced a lot of script I use to write. Unfortunately, as of Roll Up 2 you can only specify the number of record to display on a sub-grid. This in turn determines how many records are on each page of the sub-grid and how the sub-grid appears when it is rendered on a form. Well if your users are like mine, they do not want to page through the the sub-grid at 5,10, or X records a page. No, what they want is to have the paging set to 250 records per page and scroll through the records. While you can have a sub-grid display 250 records at a time, you can not constrain it to a specific height and force it to scroll.

Well to get around this issue you can use the script below which sets the RecordsPerPage and maxrowsbeforescroll parameters of the sub-grid and adjusts the height of #SUB-GRID ID#_divDataArea div element of the sub-grid. The RecordsPerPage and maxrowsbeforescroll parameters and passed to the web service that renders the sub-grid and controls how many reds care visible at a given time in a sub-grid when it is rendered. Please let me know if you find any issues of have a have a better method for addressing this particular issue.

//Warning: This code below is not supported by Microsoft

//Place this code at the start of your script
function setSubgridHeight(grdID, noRecordsDisplay, noRecordsPerPage, forceRefresh) {
/// <summary>
/// Causes sub-grid to scroll by setting the number of records to be displayed and 
/// </summary>
/// <param name="grdID" type="string">
/// ID of sub-grid *required
/// </param>
/// <param name="noRecordsDisplay" type="int">
/// Controls height of sub-grid and how many recors are displayed
/// Before applying scrolling
/// </param>
/// <param name="noRecordsPerPage" type="int">
/// Determines number of records to display per page.  If not provided
/// The value defined in the form editor will be used
/// </param>  
/// <returns type="nothing" />
  if (!IsNull(grdID)) {                
    var tbl = $("#" + grdID);

    //Adjust the sub-grid page size if desired, otherwise this is controlled by the form editor
    if (!IsNull(noRecordsPerPage)) {
      //Get reference to divGridProps element of desired grid.
      //Microsoft stores property infomrmaiton about the sub-grid within this element
      var divProps = $("#divGridProps", tbl);
      $("#recsPerPage", divProps).attr("value", noRecordsPerPage);  //Controls number of rows returned by data provider and sets the page size for the sub-grid
    }

    //Get reference to divGridParams element of desired grid.
    //Microsoft stores parameter infomrmaiton about the sub-grid within this element  
    var divParams = $("#divGridParams", tbl);  

    noRecordsDisplay = (IsNull(noRecordsDisplay) ? "5" : noRecordsDisplay);  //Default to 5 visible records at a time

    $("#RecordsPerPage", divParams).attr("value", noRecordsDisplay);  //Controls number of rows displayed in output table
    $("#maxrowsbeforescroll", divParams).attr("value", noRecordsDisplay);  //Force scroll bar to display if more records included than desired to display
  
    //Clear all of the empty TR that are added to fill the table height
    var tb = $("#" + grdID + "_d").parent().parent();
    $("tr", tb).filter(function(index) { return $(this).html() == ""; }).remove();

    //Now resize the data area of the grid
    $("#" + grdID + "_divDataArea").css("height", ((noRecordsDisplay - 1) * 25) + "px");
  
    //Refresh the grid if desired
    if(forceRefresh) { document.getElementById(grdID).control.refresh(); }
  } else {
    throw Error.argument("grdID", "grdID is null or undefined")
  }
} 

//To use you would write something like 
setSubgridHeight(#SUB-GRID ID#, 10, null, false);

Friday, July 1, 2011

How to get the Entity Type Code / Object Type Code in CRM 2011 - Part 2

This is a followup to my previous post about How to get the Entity Type Code in CRM 2011. While that method works, it requires you to go to a page and manually get the type code for the entity. What we really need is a way through script to get the entity type code / object type code by passing an entity name. Well, the code below uses Microsoft's own logic and will return the entity type code / object type code for the entity name you provide it.  Let me know if you have any trouble or have any suggestions on how to improve this.

var getObjectTypeCode = function(entityName) {
/// <summary>
/// Gets the EntityTypeCode / ObjectTypeCode of a entity
/// </summary>
/// <param name="entityName" type="string">
/// Name of entity to return object type code of
/// </param>
/// <returns type="int" /> 
 var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
 lookupService.SetParameter("entityName", entityName);
 var result = lookupService.Execute();

 if (result.Success && typeof result.ReturnValue == "number") {
  return result.ReturnValue;
 } else {
  return null;
 }
}