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.

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

No comments:

Post a Comment

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...