Tuesday, September 24, 2019

CRM remove email warning "The email below might contain script or content that is potentially harmful and has been blocked."




  1. Download and install the solution
    • You can get the latest version under this link: https://github.com/seanmcne/OrgDbOrgSettings/releases
  2. Open the solution and locate the “SecuritySettingforEmail” entry
    • Open the Solution and activate the tracking through pressing of the “Add” button.
  3. Change the “SecuritySettingforEmail” value from 1 to 3

Loop through sys columns and change data in tables to proper case

DECLARE @SQL varchar(max)
DECLARE @MyCursor CURSOR
DECLARE @TableName char(50)
DECLARE @FieldName char(50)

--Get a list of all tables in DB
if object_id('tempdb..#temp') is not null
drop table #temp
--45
select o.name TableName,c.name FieldName, t.name datatype , c.max_length , 2 keep
into #temp
from sys.objects o inner join sys.columns c on o.object_id =c.object_id inner join sys.types t on c.user_type_id =t.user_type_id
where type = 'U' and   t.precision =0 and t.max_length >0
and o.name not like 'meta%' and o.name not like 'sysd%' 
and c.name in  ('Address1', 'Address2', 'City', 'Country', 'County', 'Description','FirstName', 'LastName', 'Name',  'JobTitle', 'MiddleName')

--Display the top 3 records of each table         
SET @MyCursor = CURSOR FOR
 select rtrim(ltrim(TableName)),rtrim(ltrim(FieldName))  from #temp order by fieldname

OPEN @MyCursor
FETCH NEXT FROM @MyCursor
INTO @TableName, @FieldName
WHILE @@FETCH_STATUS = 0
BEGIN

IF @fieldname = 'Country'
BEGIN
--SET @SQL = ' SELECT TOP 3 '''+ @fieldname +''', dbo.topropercase(' + rtrim(ltrim(@fieldname)) + ') FROM  ' + rtrim(ltrim(@TableName) + ' where ' + @fieldname + ' not in (''USA'', ''US'') and len(rtrim(ltrim(' + @fieldname + ')))>2') 
SET @SQL = 'UPDATE ' + rtrim(ltrim(@TableName) + 'SET '+ @fieldname +'= dbo.topropercase(' + rtrim(ltrim(@fieldname)) + ')  where ' + @fieldname + ' not in (''USA'', ''US'') and len(rtrim(ltrim(' + @fieldname + ')))>2') 
END
ELSE
BEGIN
--SET @SQL = ' SELECT TOP 3 '''+ @fieldname +''', dbo.topropercase(' + rtrim(ltrim(@fieldname)) + ') FROM  ' + rtrim(ltrim(@TableName) + ' where ' + @fieldname + ' is not null') 
SET @SQL = 'UPDATE ' + rtrim(ltrim(@TableName) + 'SET '+ @fieldname +'= dbo.topropercase(' + rtrim(ltrim(@fieldname)) + ')  where ' + @fieldname + ' is not null') 
END

 --set @sql = 'select '+ @fieldname +' from ' + @TableName
--select @SQL
EXEC(@SQL)

FETCH NEXT FROM @MyCursor
INTO @TableName, @FieldName
END
CLOSE @MyCursor
DEALLOCATE @MyCursor

SQL funtion to change text to proper case

CREATE FUNCTION ToProperCase(@string VARCHAR(255)) RETURNS VARCHAR(255)
AS
BEGIN
  DECLARE @i INT           -- index
  DECLARE @l INT           -- input length
  DECLARE @c NCHAR(1)      -- current char
  DECLARE @f INT           -- first letter flag (1/0)
  DECLARE @o VARCHAR(255)  -- output string
  DECLARE @w VARCHAR(10)   -- characters considered as white space

  SET @w = '[' + CHAR(13) + CHAR(10) + CHAR(9) + CHAR(160) + ' ' + ']'
  SET @i = 1
  SET @l = LEN(@string)
  SET @f = 1
  SET @o = ''

  WHILE @i <= @l
  BEGIN
    SET @c = SUBSTRING(@string, @i, 1)
    IF @f = 1 
    BEGIN
     SET @o = @o + @c
     SET @f = 0
    END
    ELSE
    BEGIN
     SET @o = @o + LOWER(@c)
    END

    IF @c LIKE @w SET @f = 1

    SET @i = @i + 1
  END

  RETURN @o
END