Sitecore Item tree Removal
Introduction:
I was working on Sitecore 10, trying to create JSS Tenant. After couple of R&D, I had created lot of JSS Tenants. Thus, I decided to Delete All of them to give a new start.
Thus, I Right clicked on the JSS Tenant and went to scripts, Remove Tenant. However, it took around 10 minutes and still it was not deleted completely. The Script gave an error and stop with incomplete removal. I gave this try 3 to 4 times and later thought to take other way to get it done.
I Created a Store Procedure to delete the Item Tree. I only takes 3 to 4 seconds to get the job done.
Steps Followed:
1 - Create the given below stored procedure:
(NOTE: USE [SC10_Master] you will have to change this based on your master Database Schema Name.)
(SelectTreeFromRootId)
------------------------------------------------------------------------------------------------
USE [SC10_Master]
GO
/****** Object: StoredProcedure [dbo].[SELECTTreeFromRootId] Script Date: 6/24/2022 7:59:08 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE SELECTTreeFromRootId
@rootID NVARCHAR(MAX)
AS
--DECLARE @rootID1 NVARCHAR(MAX)
--SET @rootID1 = '7D748F8F-67FF-40F8-AFD2-DF5EFD59FB88'
BEGIN
WITH q AS
(
SELECT ID, Name, ParentID
FROM Items
WHERE ID = @rootID
UNION ALL
SELECT m.ID, m.Name, m.ParentID
FROM Items m
JOIN q
ON m.parentID = q.ID
)
SELECT *
FROM q
END
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
(DeleteTreeFromRootId)
USE SC10_Master;
GO
CREATE PROCEDURE DeleteTreeFromRootId
@rootID NVARCHAR(MAX)
AS
BEGIN
create table #FinalDelete
(
id uniqueidentifier null,
name nvarchar(256) null,
parentid uniqueidentifier null,
)
INSERT INTO #FinalDelete
EXEC SELECTTreeFromRootId @rootID;
SELECT * FROM #FinalDelete
DELETE FROM Items Where ID in (SELECT ID FROM #FinalDelete)
SELECT ID, name, parentid from Items Where ID in (SELECT ID FROM #FinalDelete)
DROP TABLE #FinalDelete
END
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
2 - Go to Sitecore to get Item ID of JSS Tanent to be deleted:
Notice, we have 1 websites under this JSS Tenant. Copy the Item ID
3 - Execute the below Query:
First see to it that you have the Respective master schema selected as shown below.
ID now is F74B7694-F2BB-43B6-8578-33C65B1700EE
Now paste the ID as value of @rootID.
SELECTTreeFromRootId @rootID = 'F74B7694-F2BB-43B6-8578-33C65B1700EE';
now click Execute As shown below
After, execution you will see all the items under your JSS Tenant. as shown below.
Cross verify and confirm at least 4 to 5 items.
4 - Execute the Delete Query:
Similar to Select Query now Execute the Delete Query as shown below.
DeleteTreeFromRootId @rootID = 'F74B7694-F2BB-43B6-8578-33C65B1700EE';
5 - Clear Sitecore Cache:
once we have deleted the JSS Tenant, we need to clear the sitecore cache else, you will still see the old Item tree output.
please change the domain (in bold) from given URL: https://sc10sc.dev.local/sitecore/admin/cache.aspx
6 - Delete the rendering for the same:
We can use same Stored Procedures to delete the Tree of JSS Rendering, I have not done the same for other as well will do it now.
Repeat the same in Template section as well.
Conclusion:
I will try to find more places where JSS tenant automatically creates Item. But for sure the same Stored procedure will work for them as well if they are created under their own Project Folder. please do let me know if we can refine this article further. all reviews are much appreciated
Comments
Post a Comment