USE [DD_ECM]
GO

UPDATE TBDD_MODULES SET DB_VERSION = '2.4.0.0' where NAME = 'Process-Manager'
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TBTF_VALIDATOR_MESSAGE](
	[GUID] [bigint] IDENTITY(1,1) NOT NULL,
	[DocID] [bigint] NOT NULL,
	[GUI_LANG_TITLE] [nvarchar](100) NOT NULL,
	[ImageIndex] [tinyint] NOT NULL,
	[Active] [bit] NOT NULL,
	[ADDED_WHEN] [datetime] NOT NULL,
	[ADDED_WHO] [varchar](100) NOT NULL,
	[CHANGED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [varchar](100) NULL,
 CONSTRAINT [PK_TBTFVALIDATOR_MESSAGE] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TBTF_VALIDATOR_MESSAGE] ADD  CONSTRAINT [DF_TBTFVALIDATOR_MESSAGE_ACTIVE]  DEFAULT ((1)) FOR [Active]
GO

ALTER TABLE [dbo].[TBTF_VALIDATOR_MESSAGE] ADD  CONSTRAINT [DF_TBTFVALIDATOR_MESSAGE_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
USE [DD_ECM]
GO


CREATE TRIGGER [dbo].[TBTF_VALIDATOR_MESSAGE_AFT_UPD] ON [dbo].[TBTF_VALIDATOR_MESSAGE]
FOR UPDATE
AS
  UPDATE TBTF_VALIDATOR_MESSAGE SET CHANGED_WHEN = GETDATE()
  FROM INSERTED
  WHERE TBTF_VALIDATOR_MESSAGE.GUID = INSERTED.GUID
GO

ALTER TABLE [dbo].[TBTF_VALIDATOR_MESSAGE] ENABLE TRIGGER [TBTF_VALIDATOR_MESSAGE_AFT_UPD]
GO

INSERT INTO [dbo].[TBDD_SQL_COMMANDS]
           (TITLE,SQL_COMMAND)
     VALUES('TF_WORKFLOW_MESSAGE','SELECT 
	CONVERT(VARCHAR(30), A.ADDED_WHEN,20) + '' - '' +  B.STRING1 as MSG,A.ImageIndex 
FROM 
	TBTF_VALIDATOR_MESSAGE A INNER JOIN 
	(SELECt * FROM TBDD_GUI_LANGUAGE_PHRASE 
	WHERE MODULE = ''PM'' AND OBJ_NAME = ''frmValidator'' AND CAPT_TYPE = ''WF_MESSAGE'') B ON A.GUI_LANG_TITLE = B.TITLE
WHERE 
	A.Active = 1 and (A.DocID = @DocID or A.DocID = 1) AND B.LANGUAGE = ''@LANGUAGE'' ORDER BY A.ADDED_WHEN DESC');


