Thursday, September 11, 2014

Search for a specific text in entire database

USE [AIRLINES]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[SearchTables]
(
     @SearchStr nvarchar(100)
)
AS
BEGIN

DECLARE @Results TABLE(ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2
nvarchar(110)
SET  @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

WHILE @TableName IS NOT NULL
BEGIN
     SET @ColumnName = ''
     SET @TableName =
     (
         SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
         FROM    INFORMATION_SCHEMA.TABLES
         WHERE       TABLE_TYPE = 'BASE TABLE'
             AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
             AND OBJECTPROPERTY(
                     OBJECT_ID(
                         QUOTENAME(TABLE_SCHEMA) + '.' +
QUOTENAME(TABLE_NAME)
                          ), 'IsMSShipped'
                            ) = 0
     )
     WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
     BEGIN
         SET @ColumnName =
         (
             SELECT MIN(QUOTENAME(COLUMN_NAME))
             FROM    INFORMATION_SCHEMA.COLUMNS
             WHERE       TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                 AND TABLE_NAME  = PARSENAME(@TableName, 1)
                 AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
                 AND QUOTENAME(COLUMN_NAME) > @ColumnName
         )
         IF @ColumnName IS NOT NULL
         BEGIN
             INSERT INTO @Results
             EXEC
             (
                 'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
                 FROM ' + @TableName + ' (NOLOCK) ' +
                 ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
             )
         END
     END
END
SELECT ColumnName, ColumnValue FROM @Results END

--To execute the above Stored Procedure
DECLARE @return_value int
EXEC @return_value = [dbo].[SearchTables]
@SearchStr = N'SAIKRISHNA'
SELECT 'Return Value' = @return_value

Sunday, August 24, 2014

Get full path of the selected file using FileUpload1 control

string  fileName = Path.GetFullPath(FileUpload1.PostedFile.FileName);

Tuesday, July 22, 2014

Everything In Active Directory via C#

Useful tool for Exporting the JavaScripts in CRM

The below tool will help you to export JavaScript from MS CRM, it is published on codeplex
Once the tool has been downloaded you can see the below window to configure the connection.


Friday, May 9, 2014

Refresh the form automatically in MS CRM

Recently I faced a scenario where the page should load automatically I,e once the record has been created internally workflow will trigger [to update the telephone number in account] which will update the created record fields for this use the below code on onload 

function Refresh()
{
var type = Xrm.Page.ui.getFormType();
if(type==2)//form opened for update
{
var x=Xrm.Page.getAttribute("telephone1").getValue();
if(x==""||x==null)
{
setTimeout("doTimer()", 8000);//for 8 seconds
}
}
}

function doTimer()
{
window.location.reload(true);

}

CRM 2011: Custom Reports & the rsProcessingAborted Error

I created a custom report for CRM 2011 in BIDS , but it is throwing an error “The report cannot be displayed. (rsProcessingAborted)” message . Out-of-the-box reports would display fine.

Reporting Error:
The report cannot be displayed. (rsProcessingAborted)



Resolution: It was not having the permission to connect to the CRM Database.
1> I then opened my SQL.
2> Went to Security -> Logins
3> Right Click NT Authority\SYSTEM (in my case)
4> Selected user Mapping
5> Checked the MSSCRM_CONFIG and Org_MSCRM with roles of :
·         CRMReaderRole
·         public
·         db_ownwer


After this refresh the database to resolve this.

Thursday, May 8, 2014

Multi Select Look up in MS CRM 2011

First create three text fields in Opportunity as new_sguid, new_stype, new_sname

Add the below code in the Web Resource
function onchange() {
    var originatingLeadValue = Xrm.Page.getAttribute("originatingleadid").getValue();
    if (IsNull(originatingLeadValue) || originatingLeadValue[0].type == "4") {
        // Lookup is null or there is a Lead, need to clear hidden fields. To clear one of them will be enough, we will be check this field during onload.
        Xrm.Page.getAttribute("new_sguid").setValue(null);
    }
    else {
        // Lookup contains Contact or User, so need to store lookup properties to our hidden fields.
        Xrm.Page.getAttribute("new_stype").setValue(originatingLeadValue[0].type);
        Xrm.Page.getAttribute("new_sguid").setValue(originatingLeadValue[0].id);
        Xrm.Page.getAttribute("new_sname").setValue(originatingLeadValue[0].name);
    }
}

function onsave() {
    var originatingLeadValue = Xrm.Page.getAttribute("originatingleadid").getValue();
    if (!IsNull(originatingLeadValue) && originatingLeadValue[0].type != '4') {
        Xrm.Page.getAttribute("originatingleadid").setValue(null);
    }
}

function onload() {
    debugger;
    lookuptypeIcons = '/_imgs/ico_16_1.gif:/_imgs/ico_16_2.gif:/_imgs/ico_16_4.gif:/_imgs/ico_16_8.gif:/_imgs/ico_16_9.gif';//add the custom entity type gif image
    lookuptypenames = 'account:1:Account,contact:2:Contact,lead:4:Lead,systemuser:8:User,team:3:Team';
    lookuptypes = '1,2,4,8,9';// Here first one is entity name, the second one we can get by opening any record for our custom entity and check out the etc value in the url and the third one is the display name for your entity. And i used /_imgs/ico_16_customEntity.gif for the icons to work with.

    var savedId = Xrm.Page.getAttribute("new_sguid").getValue();
    var savedType = Xrm.Page.getAttribute("new_stype").getValue();
    var savedName = Xrm.Page.getAttribute("new_sname").getValue();
    var savedEntityName = savedType == "8" ? "systemuser" : "contact";
    document.getElementById("originatingleadid").setAttribute("lookuptypes", lookuptypes);
    document.getElementById("originatingleadid").setAttribute("lookuptypenames", lookuptypenames);
    document.getElementById("originatingleadid").setAttribute("lookuptypeIcons", lookuptypeIcons);
    document.getElementById("originatingleadid").setAttribute("defaulttype", "4"); // default type - Lead entity
    var originatingLeadValue = Xrm.Page.getAttribute("originatingleadid").getValue();
    if (IsNull(originatingLeadValue) && !IsNull(savedId)) {
        var value = new Array();
        value[0] = new Object();
        value[0].displayClass = "ms-crm-Lookup-Item";
        value[0].keyValues = new Object();
        value[0].values = new Object();
        value[0].onclick = "openlui()";
        value[0].id = savedId;
        value[0].entityType = savedEntityName;
        value[0].typename = savedEntityName;
        value[0].name = savedName;
        value[0].type = savedType;
        Xrm.Page.getAttribute("originatingleadid").setValue(value);
    }

}
call the onload function on Opportunity onload, onsave function on Opportunity onsave, onchange on Opportunity originating lead change :)