In this blog you can find: Useful and simple code snippets in the area of Dynamics CRM (T-SQL, PowerShell). Interesting topics about (TIBCO) Scribe Insight.

Showing posts with label CRM. Show all posts
Showing posts with label CRM. Show all posts

Saturday, July 11, 2020

Get Option Set values directly from the CRM database

USE CRM_MSCRM
GO
SELECT
    sm.AttributeValue
    ,sm.Value
FROM StringMap sm with(nolock)
    inner join EntityLogicalView el with(nolock) on
        sm.ObjectTypeCode = el.ObjectTypeCode
WHERE
    AttributeName = 'statuscode'
    AND LangId = 1033
    AND el.Name = 'Opportunity'
GO

Friday, July 10, 2020

Retrieve Subsidiary Businessunits (hierarchy) via T-SQL from CRM Database

USE CRM_MSCRM
GO
DECLARE @rootName NVARCHAR(255) = 'CRM' /* Parent Business Unit Name */
DECLARE @SubsidiaryBusinesseUnits TABLE
 (businessunitid UNIQUEIDENTIFIER PRIMARY KEY, depth INT)
DECLARE @depth INT = 0
INSERT @SubsidiaryBusinesseUnits
 SELECT businessunitid ,@depth FROM BusinessUnitBase WHERE Name = @rootName
WHILE (@@rowcount > 0)
BEGIN
 SELECT @depth = @depth + 1
 INSERT @SubsidiaryBusinesseUnits
 SELECT t.BusinessUnitId
  ,@depth
 FROM BusinessUnitBase t
 WHERE EXISTS (
   SELECT *
   FROM @SubsidiaryBusinesseUnits s
   WHERE s.depth = (@depth - 1)
    AND s.businessunitid = t.ParentBusinessUnitId
   )
END
SELECT * FROM @SubsidiaryBusinesseUnits


SAMPLE: CRM Business Unit Structure


SQL Result


Thursday, July 9, 2020

Get all StateCode/StatusCode combinations directly from CRM Database

USE CRM_MSCRM
GO

declare @entityname nvarchar(50) = 'opportunity'

select
	sm.State as '[statecode]'
	,m_state.Value 'Statecode Name'

	,sm.Status as '[statuscode]'
	,m_status.Value 'Statuscode Name'

from StatusMap sm
	inner join EntityView ev on
		sm.ObjectTypeCode = ev.ObjectTypeCode
	inner join StringMap m_state on
		m_state.ObjectTypeCode = sm.ObjectTypeCode
		and m_state.AttributeName = 'statecode'
		and m_state.LangId = 1033
		and m_state.AttributeValue = sm.State

	inner join StringMap m_status on
		m_status.ObjectTypeCode = sm.ObjectTypeCode
		and m_status.AttributeName = 'statuscode'
		and m_status.LangId = 1033
		and m_status.AttributeValue = sm.Status 
where
	ev.Name = @entityname
order by
	sm.State
	,sm.Status

MSMQ - Add user privileges to queues via PowerShell

In PowerShell, the Set-MsmqQueueACL cmdlet can be used to modify the access rights of queues. Sample - Add "FullControl" permissi...