Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagesql
titlePopulating nForm Lookups and Lookup Values from a Source Table
BEGIN

DECLARE @LOOKUP_ID UNIQUEIDENTIFIER;
DECLARE @USER_ID UNIQUEIDENTIFIER; 

SELECT @LOOKUP_ID=NEWID()
SELECT @USER_ID = PRINCIPAL_ID from NFORM.PRINCIPAL where LOGIN = 'DATAINIT'; -- This is the nFORM login used for automated operations


INSERT INTO NFORM.LOOKUP
        ( LOOKUP_ID ,
          NAME ,
          CREATED_DATE ,
          CREATED_USER ,
          UPDATED_DATE ,
          UPDATED_USER ,
          IS_AVAILABLE_FOR_DROPDOWN
        )
SELECT @LOOKUP_ID , -- LOOKUP_ID - uniqueidentifier
          N'MyName' , -- NAME - nvarchar(255)
          GETDATE() , -- CREATED_DATE - datetime2
          @USER_ID , -- CREATED_USER - uniqueidentifier
          GETDATE() , -- UPDATED_DATE - datetime2
          @USER_ID , -- UPDATED_USER - uniqueidentifier
          1  -- IS_AVAILABLE_FOR_DROPDOWN - bit
          ;
 
INSERT INTO NFORM.LOOKUP_VALUE
        ( LOOKUP_VALUE_ID ,
          LOOKUP_ID ,
          NAME ,
          DESCRIPTION ,
          CREATED_DATE ,
          CREATED_USER ,
          UPDATED_DATE ,
          UPDATED_USER 
         -- , IS_ACTIVE
        )
SELECT NEWID() , -- LOOKUP_VALUE_ID - uniqueidentifier
          @LOOKUP_ID , -- LOOKUP_ID - uniqueidentifier
          MySourceTable.CODE , -- NAME - nvarchar(600)
          MySourceTable.DESCR , -- DESCRIPTION - nvarchar(600)
          GETDATE() , -- CREATED_DATE - datetime2
          @USER_ID , -- CREATED_USER - uniqueidentifier
          GETDATE() , -- UPDATED_DATE - datetime2
          @USER_ID ,  -- UPDATED_USER - uniqueidentifier

        -- , 1  -- IS_ACTIVE - bit
FROM MySourceTable;

END