Tuesday, October 18, 2016

Deleted Forms Cause Error in Publish

During recent CRM upgrades I started getting the following error on publish.
systemform With Id = {Guid} Does Not Exist
After looking through the database it was discovered that there were upgraded forms that had been marked with the component state of deleted which were causing the error. Deleting those rows marked with the component state of 2 (deleted) allowed for publishing.

*** Disclaimer: Modifying CRM data directly can void your warranty. Use at your own risk. ***
delete from systemformbase where componentstate = 2

Tuesday, October 4, 2016

Repost: Loading Assemblies from Anywhere into a New AppDomain by 2012 by Marius Bancila

If you are interested in loading assemblies into a worker domain which do not live in the base directory of that worker domain, check out this great article with code. http://www.codeproject.com/Articles/453778/Loading-Assemblies-from-Anywhere-into-a-New-AppDom

Friday, September 9, 2016

Watch Window Copy for Plugin Context Depth Issues

For those times when you are trying to figure out a plugin depth issue and you want to quickly copy/past into your watch window.

pluginExecutionContext.PrimaryEntityName
pluginExecutionContext.Depth
pluginExecutionContext.Stage
pluginExecutionContext.ParentContext.PrimaryEntityName
pluginExecutionContext.ParentContext.Depth
pluginExecutionContext.ParentContext.Stage
pluginExecutionContext.ParentContext.ParentContext.PrimaryEntityName
pluginExecutionContext.ParentContext.ParentContext.Depth
pluginExecutionContext.ParentContext.ParentContext.Stage
pluginExecutionContext.ParentContext.ParentContext.ParentContext.PrimaryEntityName
pluginExecutionContext.ParentContext.ParentContext.ParentContext.Depth
pluginExecutionContext.ParentContext.ParentContext.ParentContext.Stage
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.PrimaryEntityName
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.Depth
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.Stage
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.PrimaryEntityName
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.Depth
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.Stage
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.PrimaryEntityName
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.Depth
pluginExecutionContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.ParentContext.Stage

Thursday, August 4, 2016

Get Solutions Containing Web Resource

Snipit to determine which solutions contain a web resource.
SELECT TOP 1000 
 S.FriendlyName, 
 s.UniqueName, 
 WR.DisplayName, 
 WR.Name     
  FROM [Default_MSCRM].[dbo].[SolutionComponentBase] SC
  LEFT JOIN Default_MSCRM.dbo.SolutionBase S ON S.SolutionId = SC.SolutionId
  INNER JOIN Default_MSCRM.dbo.WebResourceBase WR ON WR.WebResourceId = SC.ObjectId
  WHERE WR.Name LIKE '%classeventscoresheet.htm%'

Thursday, April 7, 2016

Refresh ISV/WebResource after CRM 2013/2015/2016 Save Event

I had a Web Resource page which needed to refresh a jqgrid on it after some fields on a CRM form were updated and record was saved. In order to do this a ran a watcher to check to see if the modified date of the record had changed if so I ran the code to update the grid. This code is on the actual Web Resource page not the form JS. Also a quick note you may want to run another watcher to make sure window.parent.Xrm.Page is not null before you run this code.
//set the initial modified on date
var prevModifedOn = window.parent.Xrm.Page.getAttribute('modifiedon').getValue();

var xrmPageWatcher = window.setInterval(function () {
    //check to see if the date is modified, convert to string since JS doesn't know how to convert the CRM date time to a datetime object
    if (window.parent.Xrm.Page.getAttribute('modifiedon').getValue().toString() != prevModifedOn.toString()) {
    //update the previous data time so we can detect another save
    prevModifedOn = window.parent.Xrm.Page.getAttribute('modifiedon').getValue();
    //refresh our JQ grid or do whatever else you want like refresh the whole web resource etc.
    $("#grid").jqGrid('setGridParam', { data: awardsDS.generateDataTable(true) }).trigger('reloadGrid');           
    }            
}, 500);   

Monday, December 7, 2015

SQL - Determine Locking

Gets the list of sessions which are blocking others in SQL
WITH [Blocking]
AS (SELECT w.[session_id]
   ,s.[original_login_name]
   ,s.[login_name]
   ,w.[wait_duration_ms]
   ,w.[wait_type]
   ,r.[status]
   ,r.[wait_resource]
   ,w.[resource_description]
   ,s.[program_name]
   ,w.[blocking_session_id]
   ,s.[host_name]
   ,r.[command]
   ,r.[percent_complete]
   ,r.[cpu_time]
   ,r.[total_elapsed_time]
   ,r.[reads]
   ,r.[writes]
   ,r.[logical_reads]
   ,r.[row_count]
   ,q.[text]
   ,q.[dbid]
   ,p.[query_plan]
   ,r.[plan_handle]
 FROM [sys].[dm_os_waiting_tasks] w
 INNER JOIN [sys].[dm_exec_sessions] s ON w.[session_id] = s.[session_id]
 INNER JOIN [sys].[dm_exec_requests] r ON s.[session_id] = r.[session_id]
 CROSS APPLY [sys].[dm_exec_sql_text](r.[plan_handle]) q
 CROSS APPLY [sys].[dm_exec_query_plan](r.[plan_handle]) p
 WHERE w.[session_id] > 50
  AND w.[wait_type] NOT IN ('DBMIRROR_DBM_EVENT'
      ,'ASYNC_NETWORK_IO'))
SELECT b.[session_id] AS [WaitingSessionID]
      ,b.[blocking_session_id] AS [BlockingSessionID]
      ,b.[login_name] AS [WaitingUserSessionLogin]
      ,s1.[login_name] AS [BlockingUserSessionLogin]
      ,b.[original_login_name] AS [WaitingUserConnectionLogin] 
      ,s1.[original_login_name] AS [BlockingSessionConnectionLogin]
      ,b.[wait_duration_ms] AS [WaitDuration]
      ,b.[wait_type] AS [WaitType]
      ,t.[request_mode] AS [WaitRequestMode]
      ,UPPER(b.[status]) AS [WaitingProcessStatus]
      ,UPPER(s1.[status]) AS [BlockingSessionStatus]
      ,b.[wait_resource] AS [WaitResource]
      ,t.[resource_type] AS [WaitResourceType]
      ,t.[resource_database_id] AS [WaitResourceDatabaseID]
      ,DB_NAME(t.[resource_database_id]) AS [WaitResourceDatabaseName]
      ,b.[resource_description] AS [WaitResourceDescription]
      ,b.[program_name] AS [WaitingSessionProgramName]
      ,s1.[program_name] AS [BlockingSessionProgramName]
      ,b.[host_name] AS [WaitingHost]
      ,s1.[host_name] AS [BlockingHost]
      ,b.[command] AS [WaitingCommandType]
      ,b.[text] AS [WaitingCommandText]
      ,b.[row_count] AS [WaitingCommandRowCount]
      ,b.[percent_complete] AS [WaitingCommandPercentComplete]
      ,b.[cpu_time] AS [WaitingCommandCPUTime]
      ,b.[total_elapsed_time] AS [WaitingCommandTotalElapsedTime]
      ,b.[reads] AS [WaitingCommandReads]
      ,b.[writes] AS [WaitingCommandWrites]
      ,b.[logical_reads] AS [WaitingCommandLogicalReads]
      ,b.[query_plan] AS [WaitingCommandQueryPlan]
      ,b.[plan_handle] AS [WaitingCommandPlanHandle]
FROM [Blocking] b
INNER JOIN [sys].[dm_exec_sessions] s1
ON b.[blocking_session_id] = s1.[session_id]
INNER JOIN [sys].[dm_tran_locks] t
ON t.[request_session_id] = b.[session_id]
WHERE t.[request_status] = 'WAIT'
GO

SQL Currently Running Sessions

Get all current sessions running on sql instance.
SELECT r.session_id, r.status, r.start_time, r.command, s.text, 
r.wait_time, r.cpu_time, r.total_elapsed_time, r.reads, r.writes, r.logical_reads, r.transaction_isolation_level 
,r.* 
FROM sys.dm_exec_requests r 
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) s