function DetectBrowser() {
var val = navigator.userAgent.toLowerCase();
if (val.indexOf("firefox") > -1)
return "firefox";
else if (val.indexOf("opera") > -1)
return "opera";
else if (val.indexOf("msie") > -1)
return "msie";
else if (val.indexOf("safari") > -1)
return "safari";
}
Pirasanth
I Want to change the world but no one give the source code
Thursday, August 11, 2011
Detect the browser Type
Monday, January 24, 2011
Create Silverlight Application
Here I am going to share one of the Silverlight applications which I did for RND purpose and also what are the problems I have face during this application
Silverlight application is subset of WPF (window presentation foundation). Its fulfill the traditional ASP.NET application.To create Silverlight application following items we need to install
1) Visual studio 2010
2) Silverlight 4.0 development toolkit (http://silverlight.codeplex.com/)
3) Silverlight runtime
Once you install Silverlight 4.0 development kit go to visual studio open new project you will get Silverlight in the left hand side. Here there are some temples also available that are already partially completed one if we want we can continue from this template. Here I am going to explain from empty template
Visual studio -> New Project -> Silverlight -> Silverlight Application
When I select Silverlight application we will get below popup here its ask where we need to deploy this Silverlight application (WPF Control) here there are three option we can deploy to new web project , web site or MVC web project. Suppose if this solution contain any other web project this it will ask whether need to deploy to existing application or new application and also we can select Silverlight version and whether do we need RIA services. Next RND blogs I will write Silverlight application with RIA services.

Below it show the solution it contain client application (Silverlight) and server application (Hosting application)
Within the box First one is Silverlight application it will run in Silverlight not .NET frame work other one work on .NET frame work. We couldn’t add normal DLL to Silverlight application (RND Silverlight) it accept only Silverlight supportable class library because this is not run in frame work run on Silverlight framework.
When we build the Silverlight application create .XAP file within ClientBin folder. This is the one contain all XAML code for run silverlight.
Adding Services to our application
Just right click on the RNDSilverlight (Client Application) Add Services Reference and add this service to our application
Add services reference to Silverlight class as using RNDSilverlight.WCFServices; after that we can create proxy class to connect that services
Service1Client service1Client = new Service1Client();
service1Client.GetDataCompleted +=new EventHandler<getdatacompletedeventargs>(RetriveData);
service1Client.GetDataAsync("Pirasanth");
public void RetriveData(object sender, GetDataCompletedEventArgs e)
{
if (e.Error== null)
{
var data = e.Result;
}
}
Note before assign the data we need to check whether e.Error contain any value if yes we need to put some custom error message otherwise it will prompt big message.
In this binding after 1 minute I got time out issue so I have increase receive and sent timeout in the services Web.config like
<basichttpbinding>
<binding name="Binding1" closetimeout="04:50:00" opentimeout="04:50:00" receivetimeout="04:20:00" sendtimeout="04:20:00" maxbuffersize="655360000" maxbufferpoolsize="524288000" maxreceivedmessagesize="655360000">
<readerquotas maxdepth="2000000000" maxstringcontentlength="2000000000" maxarraylength="2000000000" maxbytesperread="2000000000" maxnametablecharcount="2000000000">
</binding>
</basichttpbinding>
</bindings>
But still after 1 min I got the time out issue like “WCF TimeOut Issue in Silver Light Application” so increase the time out we need to bind it manually as below
BasicHttpBinding WCFServiceBind = new BasicHttpBinding
{
CloseTimeout = new TimeSpan(0, 30, 0),
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
ReceiveTimeout = new TimeSpan(4, 0, 0),
SendTimeout = new TimeSpan(4, 0, 0),
OpenTimeout = new TimeSpan(0, 30, 0)
}; // WCF TimeOut Issue in Silver Light Application
EndpointAddress WCFServiceEndPoint = new EndpointAddress("http://localhost.RNDServices.svc");
service1Client = new Service1Client(WCFServiceBind, WCFServiceEndPoint);
service1Client.GetDataCompleted += new EventHandler<>( RetriveData);
service1Client.GetDataAsync("Pirasanth");
Note: - we couldn’t use other binding in Silverlight. Only BasicHttpBinding and TCP binding. To fix the timeout issue both services and client side we need to increase as I mention above
Now i will focus on binding datagride for that I am creating Silverlight supportable class library in that library contain class Student we can bind the data which we got from the WCF services. Before that we need to add this System.ComponentModel.DataAnnotations dll to this library for the validation and we need to implement IDataErrorInfo interface for validation
public class Student : IDataErrorInfo
{
[Range(0, 100)]
public int Age
{
get;
set;
}
public String Name
{
get;
set;
}
public string Error
{
get { throw new NotImplementedException(); }
}
public string this[string columnName]
{
get
{
return Validation(columnName);
}
}
private string Validation(string columnName)
{
switch (columnName)
{
case "Age":
if (condition)
{ return "Tax should be with in 0, 100 this range"; }
else
{ goto default; }
default:
return null;
}
}
}
After that we need to drag this datagride from the toolbar and set the binding Binding="{Binding Path=Name, Mode=TwoWay}".
After that we need to write below code to bind the ObservableCollection
public void RetriveData(object sender, GetListOfStudentCompletedEventArgs e)
{
if (e.Error== null)
{
var obj = e.Result;
ObservableCollection<student_si> lst = new ObservableCollection<student_si>();
foreach (Student item in obj)
{
lst.Add(new Student_Si
{
Age=item.Age,
Name=item.Name
});
}
gv.ItemsSource = lst;
}
}
In this way we can bind the list to datagride.Note:- if we use RIA services we don’t need to create one layer easily and quickly we can create using RIA enable Silverlight application. But problem it only we need to go with certain way. Not that much flexible.
pirasanth
Wednesday, July 28, 2010
Calling Custom Workflows In Javascript or ISV
We simply get ObjectTypeCode from crmForm.Objectid and workflow is unigue ID we can get from Workflow section. the problems is that when we call this launchOnDemandWorkflow it will frompt workflow dialog box for our confirmation after that we can't put notification whether that workflow Successed or not. in this can we can remove this pfompt box and we can put custom confirmation message and success message.
/********************* Calling Custom Workflows ************************/
//Pirasanth
ExecuteWorkflow = function(entityId, workflowId)
{
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <Request xsi:type=\"ExecuteWorkflowRequest\">" +
" <EntityId>" + entityId + "</EntityId>" +
" <WorkflowId>" + workflowId + "</WorkflowId>" +
" </Request>" +
" </Execute>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/MSCrmServices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
return(resultXml.xml);
}
/*************************Calling Web Services****************************/
this Wrokflow dialog box promf for confirmation if we press ok then ll execute the workflow bt user doesn't know this workflow successed or not..user can check from workflow section bt not ll promf

so in this case we can put custom confirmation messagebox and after scuuessed we can put notificatiopn whether theis workflow successed or no..
for the confirmation message we can put

Success Message..

Here user could understand whethere this workflow successed or not
Thursday, June 3, 2010
Filtered Lookup in CRM 4.0
<script runat="server">
protected override void OnLoad( EventArgs e )
{
base.OnLoad(e);
crmGrid.PreRender += new EventHandler( crmgrid_PreRender );
}
void crmgrid_PreRender( object sender , EventArgs e )
{
if (crmGrid.Parameters["search"] != null && crmGrid.Parameters["search"].StartsWith ("<fetch>"))
{
crmGrid.Parameters.Add("fetchxml", crmGrid.Parameters["search"]);
crmGrid.Parameters.Remove("searchvalue");
this._showNewButton = false;
}
}
</script>
For the main look up onchange event write below code
crmForm.all.ias_cityid.lookupbrowse = 1;
crmForm.all.ias_cityid.AddParam("search", "<fetch mapping="logical"><entity name="ias_cityEntity"><all-attributes><filter type="and"><condition value="'" operator="eq" attribute="ias_countryid"><condition operator="in" attribute="statecode"><value>0</value></condition></condition></filter></ALL-ATTRIBUTES>");</entity></fetch>
//remove the child lookup value
crmForm.all.ias_cityid.DataValue=null; // child lookup
// ias_cityEntity -- child lookup entity
// ias_country_id -- main lookup id
// ias_countryid -- main lookup attribute in sub entity
// ias_cityid -- sub lookup entity
Monday, March 22, 2010
Calling WCF Restful Services in Jquery
Create WCF 2010 Restful Services
Visual studio 2010 produce some online template so we can download this template and use from this online template we can get WCF REST Service Template 40(CS)
Just go to New Project - Online Templates - get WCF REST Service Template 40(CS) from this we can download restful service template. Once we download it will come under WCF directory.
Solutions look like this.
In this service1 class contain default methods some methods contain WebGet and WebInvoke. If we use WebGet work methods as get if we use WebInvoke we can specify methods as PUT, POST, DELETE depending on the situation we can use either WebGet or WebInvoke.
I wrote methods to return list of student details. Here UriTemplate is the URL for access this methods and response methods as JSON because I need to call this methods in Jquery so I use JSON format. Body style is not mandatory
<pre class="brush:html">
[WebGet(UriTemplate = "StudentsJSON",BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
Public List<Student> GetStudentCollectionJSON()
{
return new Student().getStudent();
}
Main advantage of this REST in 4.0 is we can give unique URL for each method and in WCF there is no .SVC extension. Microsoft has removed this SVC extension.
From below URL we can see all the methods here there is no .svc extension
http://localhost/Test/TestService/help
Before discuss about calling WCF Restful Services through Jquery we need to understand what is REST? Why we need to use restful services? When Microsoft introduces this REST and Restful services? Why we need to away from ASMX, WCF using SOAP base protocols? So here I am not going to explain the theory we can get to know by googling.
If we navigate through the methods “GET” we will get XML, JSON format default data
[WebGet(UriTemplate = "StudentsXML" , ResponseFormat = WebMessageFormat.Xml)]
public List<Student> GetStudentCollectionXML()
{
return new Student().getStudent();
}
Using http://localhost/Test/TestService/StudentsJSON link we will get JSON format data![]()
[WebGet(UriTemplate = "StudentsXML" , ResponseFormat = WebMessageFormat.Xml)]
public List<Student> GetStudentCollectionXML()
{
return new Student().getStudent();
}
Wednesday, February 10, 2010
CRM 4.0 Javascript Intellisense Tool
download tool
You can download tool
Thursday, February 4, 2010
how to call wcf service from jquery
First of all I have created WCF service library using visual studio 2008.Then I have added assembly reference “System.ServiceModel.Web” to my WCF library.Then import this assemply to out interface like this way “using System.ServiceModel.Web;”then declare methods in this interface
[OperationContract]
[WebInvoke(Method="POST",BodyStyle=WebMessageBodyStyle.Wrapped, ResponseFormat=WebMessageFormat.Json)]
string GetData(string value);
After that implement this methods to my class and also create new end point to accress jquery.

WCF Services Test
After that I want to access this WCF to my client application. To my client application import JQuery library to my application. Then put the reference to my page in this way
From this code you can able to access WCF in client side.
Friday, January 8, 2010
How to call web service using jquery
<script type="text/javascript">
function TestMethod1()
{
$.ajax(
{
type: "GET",
url: "http://localhost/DD/WebService1.asmx/HelloWorld",
data: "{}",
contentType: "application/json",
dataType: "json",
async: false,
cache: false,
success: function (result) {
alert(result.d);
},
error: function ()
{ alert("Unavailable"); }
});
}
</script >
Thursday, November 19, 2009
Calling web services in CRM
<script type="text/javascript >
var amount = crmForm.all.amount.DataValue;
urlWebServices= url+"/IsExceed";
var pmAmount = "&amp;amount ="+amount;
var parStringCredit=pmAccount+pmAmount ;
var oXmlHTTP_ = new ActiveXObject('Msxml2.XMLHTTP');
oXmlHTTP_.Open('POST', urlWebServices, false); oXmlHTTP_.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
oXmlHTTP_.Send(parStringCredit);
if ((oXmlHTTP_.responseXML.xml) != null &amp;&amp; (oXmlHTTP_.responseXML.xml.toString().length > 0))
{
this._RowCount = oXmlHTTP_.responseXML.selectSingleNode('boolean').text;
if(this._RowCount=='true')
{
alert('True');
}
else
{
alert('False');
}
}
</script >
Wednesday, October 28, 2009
How to connect different Domain SQL2008
If you want to connect SQL server 2008 which is in the different domain u have to use below command to connect
Steps
Go to command prompt
Type below command
runas /netonly /user: itfac\Pirasanth "C:\Program Files\Microsoft SQL Server\100
\Tools\Binn\VSShell\Common7\IDE\SSMS.exe"
itfac----domain Name Pirasanth-User Name
It will be asked password, type the password keeps in mind password not show in the command prompt
Then open SQL server authentication dialog box
Enter server name and select authentication type as window
Then press enter
Then you will see the entire database...

