Monday, June 15, 2009

Passing additional parameter in query string to a customized AdvFind.aspx form

If you ever need to pass additional parameters to a customized AdvFind.aspx or AdvFind.aspx itself from a vanilla install of CRM 4.0 you will most likely get the "Invalid parameter" error.

This can be resolved by creating the following DWORD registry entry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM called DisableParameterFilter, value=1.



After you've created the registry key you need to restart IIS. You will now be able to pass additional parameters in the querystring. In my requirements I had to pass a value on the crm form to my IFrame via the query string.

Thursday, June 11, 2009

Just a few reasons why jQuery is so useful with CRM 4.0

I will be updating the post as I find some useful scripts in jQuery while working with CRM 4.0.

Okay, so here goes...

Loading jQuery from _customscripts:


function load_script(url)
{
var x = new ActiveXObject("Msxml2.XMLHTTP");
x.open('GET', url, false); x.send('');
eval(x.responseText);
var s = x.responseText.split(/\n/);
var r = /^function\s*([a-z_]+)/i;
for (var i = 0; i < s.length; i++) {
var m = r.exec(s[i]);
if (m != null)
window[m[1]] = eval(m[1]);
}
}

//usage: normally on the page's onLoad() event
load_script("/_customscripts/jquery-1.3.2.min.js");



Cross page scripting:

//Old school jscripting:
crmForm.all.IFRAME_TOBULKMATCH.contentWindow.document.all.testval.value = crmVal;

//jQuery
$('#IFRAME_TOBULKMATCH').contents().find('testval').val(crmVal);


Need to get hold of the oid attribute value commonly found when you add a lookup field on your form sitting inside the span element?


//jQuery
var entId = $('.ms-crm-Lookup-Item').attr('oid');


Looping through the result in the Advanced Find grid is so easy with jQuery:


//jQuery
$('#' + iframe).contents().find('#gridBodyTable tr').each(function()
{
var v_oid = this.oid;

if (this.selected == true)
{
counter++;

//Do whatever you need to do here
}
});


Get hold of a specific xml element returned by one of the value attributes normally found in the crmFormSubmitMappedDataRemainder element in CRM 4.0:


//jQuery
var myVal = $($("#crmFormSubmitMappedDataRemainder")
.val()).filter("xyz_myguidval").text()


More to follow...

Custom WF Activity to send mobile text message in CRM 4.0

Creating a custom workflow activity for CRM is pretty straight forward. The approach we took was to register with an Email-to-SMS service provider to send out bulk SMS messages from CRM. The service provider provided us with an email account allowing the SMTP server to relay our messages through their server from the given account.

Following this approach all you need to do is simply send an email using the standard .NET libraries (System.Net.Mail) with a specific string format with a combination of the recipient's mobile number and service provider account (this will most defenitly be specific to your service provider). Sharepoint

Below I will give you some sample C# code to achieve this:




[CrmWorkflowActivity("Send SMS", "My Custom WF Activities")]
public partial class SendSMS: SequenceActivity
{

//DEV NOTE: Ensure that the name of the property (public string mobileNumber{}) match that of the name passed to DependencyProperty.Register
public static DependencyProperty mobileNumberProperty = DependencyProperty.Register("mobileNumber", typeof(string), typeof(SendSMS));

public static DependencyProperty messageProperty = DependencyProperty.Register("message", typeof(string), typeof(SendSMS));

[CrmInput("mobilenumber")]
[CrmDefault("")]
public string mobileNumber
{
get { return (string)base.GetValue(mobileNumberProperty); }
set { base.SetValue(mobileNumberProperty, value); }
}

[CrmInput("message")]
[CrmDefault("Type your sms message here")]
public string message
{
get { return (string)base.GetValue(messageProperty); }
set { base.SetValue(messageProperty, value); }
}

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext wfContext = contextService.Context;

ICrmService crmService = wfContext.CreateCrmService(true);

SendNewSMS(mobileNumber, message);

return ActivityExecutionStatus.Closed;
}





private void SendNewSMS(string mobileNr, string message)
{
string host = "localhost";

SmtpClient client = new SmtpClient(host);

MailAddress toAddress = new MailAddress(string.Format("{0}@myprovider.com", mobileNr));
MailAddress fromAddress = new MailAddress("account@myorg.com");

MailMessage msg = new MailMessage(fromAddress, toAddress);

msg.Subject = message;
msg.Body = string.Empty;

client.Send(msg);
}

Wednesday, June 10, 2009

jQuery with CRM 4.0

I'm currently working on a project where we apply extensive jQuery to CRM 4.0. Our client requires a lot of UI-specific validations and business logic, mostly required on the front-end. Being a web developer I always try to shy away from traditional JavaScript when it comes to client-side programming.

Using jQuery makes life a whole lot easier in general and more so in CRM 4.0 considering the fact that you constantly need to manipulate the DOM to perform client-side tasks. Most of the simple tasks can be achieved by one line of code saving a lot of development time and improving overall productivty of the development team.

I strongly suggest that every development team working with CRM 4.0 invest in something like jQuery
.