Tuesday, 18 December 2012

using queryexpression in c# to retreieve data

to retrieve data from crm  2011
we can use queryexpression.
first create condition expression.
then filter expression.
then query expression.

this code for login credential checking in crm 2011.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.ServiceModel.Description;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Xrm.Sdk.Query;
using System.Configuration;
using Sulekha.Order.CrmSdk;
using System.Linq.Expressions;
using Xrm;
using System.Data.SqlClient;
using System.Configuration;


namespace Sulekha.Order
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new

            Entity contacts = new Entity("contact");


            string user = username.Text.ToString();
            string pass = password.Text.ToString();

           
       

            ClientCredentials credentials = new ClientCredentials();
            credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            Uri OrganizationUri = new Uri("http://crmserver/databaseCRM/XRMServices/2011/Organization.svc");
            Uri HomeRealmUri = null;
            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
            {
                Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;

              


                ConditionExpression condition = new ConditionExpression();
                condition.AttributeName = "firstname";
                condition.Operator = ConditionOperator.Equal;
                condition.Values.Add(user);

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "lastname";
                condition1.Operator = ConditionOperator.Equal;
                condition1.Values.Add(pass);

                FilterExpression filter1 = new FilterExpression();
                filter1.Conditions.Add(condition);
                filter1.Conditions.Add(condition1);

                QueryExpression query = new QueryExpression("contact");
                query.ColumnSet.AddColumns("firstname", "lastname");
                query.Criteria.AddFilter(filter1);
               

                EntityCollection result1 = serviceProxy.RetrieveMultiple(query);

                if (result1.Entities.Count > 0)
                {
                    ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('valid Username and Password')</script>");

                }
                else
                {
                    ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('invalid Username and Password')</script>");
                }                  



            
               

            }
        }
    }
}

ref :

http://mileyja.blogspot.in/2011/07/convert-queryexpression-to-fetchxml.html

http://stackoverflow.com/questions/8669611/how-to-write-queryexpression-for-following-query

http://msdn.microsoft.com/en-us/library/gg334688.aspx


OptionSetValue osv = (OptionSetValue)entities.Attributes["statuscode"];
                        if (osv.Value == 1)
                        {
                            dr["Order Status"] = "New";
                        }
                        if (osv.Value == 2)
                        {
                            dr["Order Status"] = "Pending";
                        }


                        //dr["Order Status"] = osv.Value;
for optional set value

Thursday, 6 December 2012

plugin using by Developer tool kit

Developer tool kit :
sdk-- tools-- developer toolkit.

we need to install the developer toolkit.
for this first we can install WIF
http://support.microsoft.com/kb/974405
we can download and install.
after that install the developer tool kit.

open the Visual Studio you will get the Dynamic crm tab.
choose the new visual studio solution template.
give the name and click on ok.
you will get the connection:
give the server name. (crmsever).
choose http or https.
default credentials.
then  select the organization and solution.
click ok.
automatically it will show the crm
right click on entity and create wrapper class ( early bound).
it will come as entity.cs near by plugin.cs.
use the namespace in using area.
select the entity where we need to create plugin.
right click and select the create plugin option.
there we need to give the plugin message.
give the signing.
click on project and deploy.

sample code :


IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;
            var orgServiceContext = new OrganizationServiceContext(service);

            if (context.InputParameters.Contains("Target") &&
                             context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parmameters.
                Entity entity = (Entity)context.InputParameters["Target"];
                // TODO: Implement your custom Plug-in business logic.
                var newCooldrink = entity.ToEntity<new_cooldrink>();
                newCooldrink.new_productcount = 50;
            }

ref:
http://akilanaki.blogspot.in/2012/09/crm-2011-plugin-tips.html
http://blog.thinketg.com/blog/ben-klopfer/how-to-deploying-plugins-with-the-microsoft-dynamics-crm-2011-developer-toolkit-tutorial
http://blogs.msdn.com/b/crm/archive/2011/01/11/a-better-way-to-learn-linq-to-crm-linqpad-plugin-for-ms-crm-2011-is-available.aspx

Friday, 30 November 2012

check box in SSRS

Senario:

based on the two optional set or optional set values we need to show
check boxes in the SSRS.

for this Refer :
http://kkryczka.wordpress.com/2010/12/09/how-to-display-checkbox-on-report/

http://www.mindfiresolutions.com/Including-Checkbox-in-SQL-Server-Reporting-1163.php

http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/

First create a  report.
in that select the two optional set

Ex : Stock Available or Stock Not Available.

change the Font to "wingdings".
then go to the expression:

=iif(First(Fields!new_stockavilability.Value, "DataSet1")= false,chr(0254),chr(0168))

if it is the Optional set:

=iif(First(Fields!new_regionof.Value, "DataSet1")=100000002,chr(0254),chr(0168))

then you will get the check boxes in report.

Tuesday, 20 November 2012

Check box Onclick Event in crm 2011


Senario:

we are using the checkboxes in crm 2011.
doing some customizations based on the checkboxes.
but the problem is :
After clicking on the checkbox, you need to click outside the box then only function will execute.

for overcome this problem:

just we need to give the one extra function in onload event.

ex ;
my check box field is : new_stockdelivered

then the function in onload event is :


function onload()
{
crmForm.all.new_stockdelivered.onclick = function()
{
    crmForm.all.new_stockdelivered.FireOnChange();
}
}

for suppose :
i have two fields :
new_stockdelivered and new_stockdelivereddate.
if you check on stock delivered then only date will be enable.

first give the onchange function :


function stockdate()
{
var myAttribute = "new_stockdelivered";
var myControl = Xrm.Page.ui.controls.get(myAttribute);
var detailamt= myControl.getAttribute().getValue();
if(detailamt==true)
{
Xrm.Page.getControl("new_stockdelivereddate").setDisabled(false);
}
else
{
Xrm.Page.getControl("new_stockdelivereddate").setDisabled(true);
}
}

it is in onchange event and onload event.

and extra in onload event :


function onload()
{
crmForm.all.new_stockdelivered.onclick = function()
{
    crmForm.all.new_stockdelivered.FireOnChange();
}
}

it will give immediate effect after click on the checkbox




Tuesday, 6 November 2012

using HTML Web resource in crm 2011

First create a HTML code.
senario:
giving colours in form:

HTML code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Test Page </title>
    <script type="text/javascript">
        var Xrm;
        if (window.opener) { Xrm = window.opener.Xrm; }
        else if (window.parent) { Xrm = window.parent.Xrm; }

        onload = function () {
            var myOptionSet = Xrm.Page.data.entity.attributes.get("new_flag");
            // var optionSetValue = myOptionSet.getValue();
            var optionSetText = myOptionSet.getText();
            document.bgColor = optionSetText;
            //alert(optionSetValue + " " + optionSetText);
        }
</script>
</head>
<body>
</body>
</html>

Create Web resource:
paste the code in Source place:



just add like web resource in the form

u will get like:



another example:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>trying</title>
 
    <script id = "demo" type="text/javascript">
        var Xrm;
        if (window.opener) {
            Xrm = window.opener.Xrm;
        }
        else if (window.parent) {
        Xrm = window.parent.Xrm;
    }
    onload = function () {
        debugger;
        var myname = Xrm.Page.data.entity.attributes.get("new_name").getValue();
        var mytest = Xrm.Page.data.entity.attributes.get("new_test").getValue();
        document.write(myname);
        document.write(mytest);
           }
   
    </script>
</head>
<body>
</body>
</html>



onload = function () {
        debugger;
        var myname = Xrm.Page.data.entity.attributes.get("new_name").getValue();
        var mytest = Xrm.Page.data.entity.attributes.get("new_test").getValue();
        var table = "<table border='1'><tr><td> Name </td> <td> Test </td> </tr><tr><td>" + myname + "</td><td>" + mytest + "</td></tr></table>";
        document.write(table);
        //document.write(mytest);


    }

some links for crm 2011