Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
if exists(select * from sys.objects where object_id = object_id('dbo.pp_CopyDashboard') and objectproperty(object_id,'IsProcedure')=1)
drop proc dbo.pp_CopyDashboard
create procedure dbo.pp_CopyDashboard @companyID int, @dashboardID int AS
DECLARE @id int
DECLARE @ids table([id] int)
Insert Into Dashboard ([CompanyID], [Name], [DefaultOwnerRole], [ScreenID], [AllowCopy], [Workspace1Size], [Workspace2Size], [IsPortal], [CreatedByID], [CreatedByScreenID], [CreatedDateTime], [LastModifiedByID], [LastModifiedByScreenID], [LastModifiedDateTime])
OUTPUT inserted.DashboardID INTO @ids
Select @companyID, [d].[Name] + '-Copy', [d].[DefaultOwnerRole], NULL, [d].[AllowCopy], [d].[Workspace1Size], [d].[Workspace2Size], [d].[IsPortal], [d].[CreatedByID], [d].[CreatedByScreenID], [d].[CreatedDateTime], [d].[LastModifiedByID], [d].[LastModifiedByScreenID], [d].[LastModifiedDateTime]
From Dashboard d
Where d.DashboardID = @dashboardID
Select top 1 @id = id from @ids
Insert Into Widget ([CompanyID], [DashboardID], [OwnerName], [Caption], [Column], [Row], [Workspace], [Width], [Height], [Type], [Settings], [CreatedByID], [CreatedByScreenID], [CreatedDateTime], [LastModifiedByID], [LastModifiedByScreenID], [LastModifiedDateTime], [NoteID])
Select @companyID, @id, [w].[OwnerName], [w].[Caption], [w].[Column], [w].[Row], [w].[Workspace], [w].[Width], [w].[Height], [w].[Type], [w].[Settings], [w].[CreatedByID], [w].[CreatedByScreenID], [w].[CreatedDateTime], [w].[LastModifiedByID], [w].[LastModifiedByScreenID], [w].[LastModifiedDateTime], [w].[NoteID]
From Widget w
Where w.DashboardID = @dashboardID
Begin tran
exec pp_CopyDashboard 2, 33
Rollback tran
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.