Handling The Broken ClearCompanies Script

March 29th, 2018 by

As I covered in this post there is a problem in the Clear Companies script available from Microsoft which breaks the User Smart List Master (ADH00100) table.

The issue is that the clear companies script deletes rows from the ADH00100 table when the relevant database doesn’t exist. This will only be a problem for sites which have SmartList objects created with SmartList Designer, which explains why I haven;t seen the problem more often.

I posted the code which can be used to update the clear companies script, but if you don;t want to maintaina custom version of this script, there are two actions you can take.

If you know of this issue in advance of running the clear companies script, you can build into your process the runing of a script against the table to change all of the CMPANYID entries in the table to the number of a company which does exist:

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales (CC BY-NC-SA 2.0 UK).
*/
UPDATE
	['User Smart List Master']
SET
	CMPANYID = (SELECT TOP 1 CMPANYID FROM SY01500 ORDER BY CMPANYID DESC)
FROM
	ADH00100 AS ['User Smart List Master']
WHERE
	CMPANYID <> 0
AND
	(SELECT COUNT(database_id) FROM sys.databases AS ['System Databases'] WHERE ['User Smart List Master'].CMPANYID = ['System Databases'].database_id) = 0
GO

This script is configured to only update the CMPANYID field when the relevant database doesn;t exist or the field is set to 0.

If you haven’t identified the issue before running the Clear Companies script, you can copy the settings from the live server (you may need to create a linked server first) or from a restored version of your system database (named DYNAMICS by default):

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales (CC BY-NC-SA 2.0 UK).
*/
INSERT INTO DYNAMICS.DBO.ADH00100
    (ASI_Favorite_Dict_ID
    ,ASI_Favorite_Type
    ,ADHParentFavoriteType
    ,ADHListName
    ,USERID
    ,CMPANYID
    ,ADHExcelReportDeployed
    ,ViewName
    ,Workflow_Status
    ,ViewScript)
--VALUES
	(SELECT
		ASI_Favorite_Dict_ID
		,ASI_Favorite_Type
		,ADHParentFavoriteType
		,ADHListName
		,USERID
		,CMPANYID
		,ADHExcelReportDeployed
		,ViewName
		,Workflow_Status
		,ViewScript
	 FROM
		[sqlserversqlinstance].DYNAMICS.DBO.ADH00100 AS ADHO
	 WHERE
		(SELECT
			COUNT(*)
		FROM
			DYNAMICS..ADH00100 AS ADHI
		WHERE
			ADHO.ASI_Favorite_Dict_ID = ADHI.ASI_Favorite_Dict_ID
		AND
			ADHO.ASI_Favorite_Type = ADHI.ASI_Favorite_Type) = 0)
GO

Read original post Handling The Broken ClearCompanies Script at azurecurve|Ramblings of a Dynamics GP Consultant

Source: azurecurve

Leave a Reply