Thursday, November 14, 2013

Group by one column and select more than one column Sql query

Some times you required to select multiple columns but doesn't required to group by more than on column, to achieve this follow the example given below:


declare @tempTbale table(ID int identity(1,1),col1 varchar(20),col2 varchar(20),col3 varchar(20),col4 varchar(20),col5 int)
insert into @tempTbale values('h','x','y','p',10)
insert into @tempTbale values('k','m','y','p',10)
insert into @tempTbale values('l','n','y','p',40)
insert into @tempTbale values('h','x','y','q',30)
insert into @tempTbale values('h','x','y','r',20)
insert into @tempTbale values('s','u','y','r',10)

select MIN(col1) as col1,MIN(col2) as col2,MIN(col3) as col3,col4,SUM(col5) as col5 from @tempTbale
group by col4

Tuesday, November 5, 2013

ASP.NET fails to detect IE10 causing _doPostBack is undefined JavaScript error or maintain FF5 scrollbar position

There is a bug in the browser definition files that shipped with .NET 2.0 and .NET 4, namely that they contain definitions for a certain range of browser versions. But the versions for some browsers (like IE 10) aren't within those ranges any more. Therefore, ASP.NET sees them as unknown browsers and defaults to a down-level definition, which has certain inconveniences, like that it does not support features like JavaScript.

for more information please visit SCOTT HANSELMAN

A similar bug affects Firefox versions 5 and above, where support for using JavaScript to reposition the scrollbar in the browser is not detected. This basically breaks the MaintainScrollbackPositionOnPostBack property for Web Forms pages.
These "misdetection" bugs affect Web Forms pages in both ASP.NET 2 and ASP.NET 4. If you are using ASP.NET Web Pages, or if you're using ASP.NET MVC or ASP.NET Web Pages and are not using the Browser object to detect JavaScript support, you will not be affected.

FIXES

There are two ways to fix this: one is a machine-wide fix, the other is a way to fix individual sites.

MACHINE-WIDE FIXES

We're releasing a hotfix that will fix these, which you'll be able to get to via some KB articles. These KBs with fixes are live and are the best way to update your system. The fixes solve the browser-detection issue forever for all sites on a machine. These will be rolled up into future versions of the framework and will eventually also be on Windows Update.
What the fixes do is update the ie.browser and firefox.browser files in\Windows\Microsoft.NET\Framework\\Config\Browsers with new and future-proofed versions of these browser definitions. Nothing else is affected.

SITE-ONLY FIXES

App_BrowsersIf you don't have access to the whole machine and/or just want to update a single project, use NuGet to install the App_BrowsersUpdate package. Your site structure in Solution Explorer will then look like the image at right. Note that NuGet uses .NET 4, so for systems that have only .NET 2, you'll need to get the ZIP file and put the new browser files in App_Browsers manually.
Updating the whole machine is the preferred way to fix this.
Note: To install NuGet, follow the below steps
1) Go to VS.NET > Tools > Extension Manager
2) Select Install NuGet from OnLine Gallary
3) Now search App_Browser in the Extension Manager window and click install, it will add one folder with name "App_Browser" and two browser file one for IE and one for FireFox.
4) Add The below script in the body of master page
 <script language="javascript" type="text/javascript">
        //debugger;
        if (typeof (Sys) !== 'undefined' && Sys.Browser.agent === Sys.Browser.InternetExplorer && (Sys.Browser.version === 10 || Sys.Browser.version === 9)) {

            Sys.WebForms.PageRequestManager.getInstance()._onFormElementActive = function Sys$WebForms$PageRequestManager$_onFormElementActive(element, offsetX, offsetY) { if (element.disabled) { return; } this._activeElement = element; this._postBackSettings = this._getPostBackSettings(element, element.name); if (element.name) { var tagName = element.tagName.toUpperCase(); if (tagName === 'INPUT') { var type = element.type; if (type === 'submit') { this._additionalInput = encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value); } else if (type === 'image') { this._additionalInput = encodeURIComponent(element.name) + '.x=' + Math.floor(offsetX) + '&' + encodeURIComponent(element.name) + '.y=' + Math.floor(offsetY); } } else if ((tagName === 'BUTTON') && (element.name.length !== 0) && (element.type === 'submit')) { this._additionalInput = encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value); } } };
        }
     </script>


Immediately Disable Button after On Click - ASP.net/Javascript

In one common scenario it will be helpful if you required to submit payment information online "click only once, or you may receive multiple charges. Or your specific requirement to click only once.

In C#

protected void Page_Load(object sender, EventArgs e)
{
                btnName.Attributes.Add("onclick", @"MovetoTop(); this.disabled = true; " +  this.Page.ClientScript.GetPostBackEventReference(btnName, null) + ";");
}

MovetoTop is the another function used to find the top of the webpage.

function MovetoTop() {      
        $("html, body").animate({ scrollTop: 0 }, "slow");
}

Sunday, October 27, 2013

Trigger N:N Association event and Dassiciation event in CRM Plugin in MS CRM 4.0

This Information is copied from Chandan's CRM Blog, so for more information please visit Chandan Blog

===================================================================================================
-- Enable Associate and Disassociate Plug-in Events 
-- execute the following query to CRM database, it will add two entries in SdkMessageFilterBase 
-- 'DisassociateEntities' and 'AssociateEntities' from SdkMessageBase which is not listed
-- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
USE CrmDev_MSCRM
GO

-- Find the deployments SDK Filter ID for the
-- Associate and Disassociate Entity SDK Messages
DECLARE @DisassociateEntitiesFilterId uniqueidentifier
DECLARE @AssociateEntitiesFilterId uniqueidentifier
SET @DisassociateEntitiesFilterId = (SELECT SdkMessageId FROM SdkMessageBase WHERE [Name] = 'DisassociateEntities')
SET @AssociateEntitiesFilterId = (SELECT SdkMessageId FROM SdkMessageBase WHERE [Name] = 'AssociateEntities')

-- Enable the Associate and Disassociate Filters to be valid for custom processing
-- Custom Processing means "you register plug-ins against it"
-- Note: We only do this for the "generic" (OTC == 0) case, just to be safer
UPDATE SdkMessageFilterBase SET IsCustomProcessingStepAllowed = 1 WHERE SdkMessageId = @DisassociateEntitiesFilterId AND PrimaryObjectTypeCode = 0
UPDATE SdkMessageFilterBase SET IsCustomProcessingStepAllowed = 1 WHERE SdkMessageId = @AssociateEntitiesFilterId AND PrimaryObjectTypeCode = 0
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The above query will enable the 'DisassociateEntities' and 'AssociateEntities' message in the plugin registration tool. While registering the plugin select the entity name as ‘none’

While executing the plugin you will be getting four parameter as input parameters from the plugin context along with the other properties : 

1. Related Entity1 guid and entity name
2. Related Entity2 guid and entity name
3. Relation hsip name (nothing but intersect hidden N:N entity name)
4. Optional parameter.

Using these value you can implement you logic.

Sample Code for N:N relationship with a custom entity and Sytem User:

public void Execute(IPluginExecutionContext context)

try
{
crmservice = context.CreateCrmService(true);

if (context.MessageName == "AssociateEntities")


if (context.InputParameters.Properties["RelationshipName"].ToString() == "new_new_customentity_systemuser")
{
string oId = string.Empty;
string SharedUserId = string.Empty;

oId = (context.InputParameters.Properties["Moniker1"] as Moniker).Id.ToString();

SharedUserId = (context.InputParameters.Properties["Moniker2"] as Moniker).Id.ToString();

// write you logic here

}
}

}
catch (System.Web.Services.Protocols.SoapException ex)
{
LogWriter.LogInfo(ex.ToString());
}

catch (Exception ex)
{
LogWriter.LogInfo(ex.ToString());
}
}

Note : As we have defined 'none' as the entity name while registering the plugin, so this plugin will get triggered when ever user will do add existing or romove existing, for any entity. So while writing the logic relationship name is required to identify from where plugin has been triggered. 

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...