Archive for the ‘JavaScript’ Category
|jQuery & ASP.NET UpdatePanel
Monday, November 9th, 2009
For some reason jQuery effects / configurations are lost during a partial page postback when using the UpdatePanel.
A good example is when you’re using the jQuery Datepicker plugin. After a partial page postback the date formatting are lost and it revert back to the defaults.
Here is a quick way to work around it:
1. Hook an event to your page’s onload event. In this case I’ve attached the page’s onload event to a JavaScript function called “load”.
<body onload="load()">
2. Call the Sys.WebForms.PageRequestManager.getInstance().add_endRequest() event exposed by ASP.NET and reference the JavaScript function name (the handler method) as parameter. This event is fired when an asynchronous postback is finished and control has been passed back to the browser
//Function called one page load
function load()
{
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(PostAJAXRefresh);
}
3. Include all jQuery effects in the handler method referenced by add_endRequest(PostAJAXRefresh)
//all jQuery effects need to be placed here again to keep effects after partial AJAX page postback
function PostAJAXRefresh()
{
//jQuery UI - datepicker
$(function() {
$("#ctl00_ContentPlaceHolder2_txtDateSent").datepicker({ dateFormat: 'm/d/yy' });
$("#ctl00_ContentPlaceHolder2_txtDateFrom").datepicker({ dateFormat: 'm/d/yy' });
$("#ctl00_ContentPlaceHolder2_txtDateTo").datepicker({ dateFormat: 'm/d/yy' });
});
Posted in ASP.NET, HTML, JavaScript, jQuery | No Comments »
Just a few reasons why jQuery is so useful with CRM 4.0
Friday, June 12th, 2009
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()
Tags: CRM, jQuery
Posted in C#, CRM, JavaScript, jQuery | No Comments »
Custom WF Activity to send mobile text message in CRM 4.0
Thursday, June 11th, 2009
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).
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);
}
Posted in C#, CRM, HTML, JavaScript, jQuery | No Comments »
You are currently browsing the archives for the JavaScript category.
-->