MS CRM 2011 Outlook Client x64 on Windows8

With many thanks to Merlin Schwaiger – Senior CRM Consultant at PowerObjects for writing this post on how to support MS CRM 2011 Outlook Client on Windows and Outlook 2013.

http://crmwizard.blogspot.nl/2011_02_01_archive.html

Long story shortened:

  • The x64 installer for the CRM 2011 Outlook client does not include everything necessary for the client to work.
  • You must download the x64 installer for SQL Compact 3.5.
  • You must upgrade the x64 version of SQL Compact 3.5 to version 3.5.8082.0 with the hotfix.
  • At this point the Outlook client should be able to connect to your CRM 2011 organization.
Advertisements

JavaScript executed from Ribbon on GridView

I had to fix the following.
Disable the Activate button on subentity records based on some value of the parent record.

The disabling should be done on the Edit-form… but in the subgrid as well.
The absense of the webresources on the subgrid was the challenge.
Here’s how:

function EnableActivateButton() {
   if (quoteid === "" && contractid === "") { return false; } 

   try {
      var varMyValue = Xrm.Page.getAttribute("CRMFieldSchemaName").getValue(); 
   }
   catch (e) {
      var entity = document.parentWindow.parent.Xrm.Page.data.entity.getEntityName(); 
      var recordid = document.parentWindow.parent.Xrm.Page.data.entity.getId(); 
      if (recordid === "") { return false; }
   }
}

Load JavaScript WebResource at runtime

Update... added Browser-agnosticity


function LoadWebResource(resource)
{
   var httpRequest = _createXMLHttpRequest();
   httpRequest.open("GET", Xrm.Page.context.getServerUrl() + "/webresources/" + resource, false);
   httpRequest.send(null);
   try {
      eval(httpRequest.responseText);
   }
   catch (e) {
      alert("Error loading " + resource + ":\n" + e.description);
   }
}

// Browser-agnostic factory function
function _createXMLHttpRequest()
{
   if (window.XMLHttpRequest) {
      return new XMLHttpRequest();
   } else if (window.ActiveXObject) {
      return new ActiveXObject('Microsoft.XMLHTTP')
   } else {
      _error("Could not create XMLHttpRequest on this browser");
      return null;
   }
} 


------



function LoadWebResource(resource) {    var orgName = Xrm.Page.context.getOrgUniqueName();    var httpRequest = new ActiveXObject("Msxml2.XMLHTTP");    httpRequest.open("GET", "/" + orgName + "/webresources/" + resource, false);    httpRequest.send(null); try {       eval(httpRequest.responseText); } catch (e) {       alert("Error loading " + resource + ":\n" + e.description);    } }

Impersonation for SharePoint 2010 LINQ to DataContext

Impersonation in SharePoint is not really the hardest to do. However the C# code snippet below was sort of new for me. In order to obtain impersonation for a DataContext, that was something.

Impersonation for the ClientContext … but the LINQ DataContext is constructed in another way… and by default using the current user… regardless the user you’ve set in SPContext.

So… here it is.

 

strUrl = SPContext.Current.Web.Url;

HttpContext backupContext = HttpContext.Current;
try
{
  
SPUserToken userToken = null;
  userToken =
SPContext.Current.Web.AllUsers[“SHAREPOINT\\system”].UserToken;

  // if there is a SPContext make it is as null so LINQ won’t execute under current context
  
if (SPContext.Current != null)   HttpContext.Current = null;

  SPSecurity.RunWithElevatedPrivileges(delegate() {
    using (SPSite oSite = newSPSite(strUrl, userToken)) {
      using (SPWeb oWeb = oSite.OpenWeb()) {
                               // creating a new HttpContext under elevated permission and
             // setting it as current control context web,
             // because of this the code will be running under elevated permission.

        HttpRequest httpRequest = newHttpRequest(“”, oWeb.Url, “”);
        HttpContext.Current = newHttpContext(httpRequest, new HttpResponse(new System.IO.StringWriter()));
        
SPControl.SetContextWeb(HttpContext.Current, oWeb);

        using (SomeDataContext dc = SomeDataContext(oWeb.Url)) 
        
{
          var comments = from c in dc.SomeDataContext
                         where c.Var1 == someVariable 
                        
select c;
                    }
      }
    }
  });

}

catch (Exception ex) {}
finally {
   // make sure that you are setting the actual SPContext back
   //
after your operation and make SharePoint happy J

   if (SPContext.Current != nullHttpContext.Current = backupContext;
}

Search SharePoint 2010 Managed Metadata Terms with an Ampersand

Already struggling with the poor functionality of the web service interface of the Taxonomy web service of SharePoint 2010, I stumbled upon another challenge.

I was building a MS CRM 2011 Plugin that populates the SharePoint Term Store using the Taxonomy web service (http://<sharepointurl>/_vti_bin/TaxonomyClientService.asmx).
The first problem was the poor functionality of the web service like being unable to add Labels to Terms.
This cannot be fixed worked around.

Then I had to query SharePoint for a Term that contained an ampersand.
Adding the Term was not a problem when the XML was escaped properly.

string _newterm = “V&D”;

_newterm = _newterm.Replace(“&”, “&amp;”).Replace(“<“, “&lt;”).Replace(“>”, “&gt;”).Replace(“\””, “&quot;”).Replace(“‘”, “&apos;”);

 

But when the SharePoint is queried for a certain Term… it works slightly different.

The TermStore can be queried for example using “GetTermsByLable()”

 

string TermXml = SPTaxService.GetTermsByLabel(TermLabel,

1033,


StringMatchOption.ExactMatch,

10,

NewTermXml,


false);

 

When you send use the TaxonomyClientService.asmx, the service will not find your term, even though when you created it you used the exact same string.

The reason is that an & will be stored by SharePoint as \uFF06

So when you wanna search for a Term, make sure you replace the ampersand… like…

 

string XmlTerm = “<newTerms><newTerm label=\”” + _newterm.Replace(“&”, “\uFF06”) + “\” clientId=\”1\” parentTermId=\”” + Guid.Empty + “\”></newTerm></newTerms>”);

 

The weird thing is, that the VS2010 Debugger still will show you the &amp;
The result from SharePoint is the right one…

So …replacing the & with &amp; does not work..!

Disclose MS CRM Online 2011 data in SharePoint 2010 Online

Thanks to LightningTools following blog post, I was able to quickly disclose CRM Online data is SharePoint Online.
Check out this post.

http://www.lightningtools.com/blog/archive/2012/02/20/crm-2011-online-and-sharepoint-2010-integration-through-business-connectivity.aspx

I am working myself working on the post of connecting to SharePoint 2010 Online from MS CRM 2010 Workflow or Plugin Assembly. The workflow assembly is not supported in MS CRM 2011 Online just yet… but the beta of RU8 is released. The wait is for the RU for MS CRM 2011 Online.

Check out my blog… I will post the solution shortly.

Localized ASP.NET RangeValidator with correct DateFormat

I needed a RangeValidator for some date-fields on my ASP.NET pages.
The pages are localized and translated… so the date-formats need to change accordingly.

All was well… until I added a minimum and maximum value for the RangeValidator… something like 1-1-1900 and 1-1-2100.
I got a really cool error:

The value ‘1-1-1901’ of the MaximumValue property of ‘rangevalidatorStartDate’ cannot be converted to type ‘Date’.

 

So I figured… I need to localize the Min and Max date-string:
So I added this in the code behind.

 

rangevalidatorStartDate.MinimumValue = DateTime.MinValue.AddYears(1900).ToShortDateString();

 

The error was not fixed yet… because… you need to localize the parsing of the date according to Culture of the page.
Then the code looks like this.

protected
void Page_Load(object sender, EventArgs e)

{

IFormatProvider culture = new
CultureInfo(Session[“MyCulture”].ToString(), true);

 

string minDate = DateTime.Parse(DateTime.MinValue.AddYears(1900).ToShortDateString(), culture).ToShortDateString();

string maxDate = DateTime.Parse(DateTime.MinValue.AddYears(2100).ToShortDateString(), culture).ToShortDateString();

 

rangevalidatorStartDate.MinimumValue = minDate;

rangevalidatorStartDate.MaximumValue = maxDate;

}

 

 

Then the markup looks like this.

 

<td><asp:TextBox
ID=”txtStartDate” runat=”server”
/>


<asp:RequiredFieldValidator

ID=”StartdateFieldValidator” runat=”server”

        ControlToValidate=”txtStartDate”

        ForeColor=”red”


ErrorMessage=””


Text=”*”

        Display=”Dynamic”

        CssClass=”validation-message” Width=”7px”
/>


<asp:RangeValidator


runat=”server”


ID=”rangevalidatorStartDate”


Type=”Date”


ControlToValidate=”txtStartDate”


ErrorMessage=”<%$Resources:eService,entityeditor_invaliddatemessage%>


Display=”None”
/>

</td>