OBJECT Codeunit 14123507 History and Security Integr.
{
  OBJECT-PROPERTIES
  {
    Date=07/22/10;
    Time=12:00:00 PM;
    Version List=ES1.00.47;
  }
  PROPERTIES
  {
    OnRun=BEGIN
          END;

  }
  CODE
  {
    VAR
      Text001@1001 : TextConst 'ENU=History and Security integration objects has not been imported.';
      Text002@1240520008 : TextConst 'ENU=History Table Setup has been copied. %1 records inserted.';

    PROCEDURE CopyHistoryTableSetup@1240520008();
    VAR
      ESLimitedAccessObject@1240520009 : Record 14123522;
      ESLimitedAccessObject2@1240520010 : Record 14123522;
      HistoryTableSetup@1240520008 : Record 14001002;
      ModifiedRecords@1240520011 : Integer;
      InsertedRecords@1240520012 : Integer;
    BEGIN
      ESLimitedAccessObject.RESET;
      ESLimitedAccessObject.SETCURRENTKEY("History Table ID");
      ESLimitedAccessObject.SETFILTER("History Table ID",'<>0');
      ESLimitedAccessObject.SETRANGE("Object Type",ESLimitedAccessObject."Object Type"::Table);
      IF ESLimitedAccessObject.FIND('-') THEN
        REPEAT
          ESLimitedAccessObject2 := ESLimitedAccessObject;
          ESLimitedAccessObject2.VALIDATE("History Table ID",0);
          ESLimitedAccessObject2.MODIFY(TRUE);

          ModifiedRecords := ModifiedRecords + 1;
        UNTIL ESLimitedAccessObject.NEXT = 0;

      ESLimitedAccessObject.RESET;
      ESLimitedAccessObject.SETCURRENTKEY("Security Table ID");
      ESLimitedAccessObject.SETFILTER("Security Table ID",'<>0');
      ESLimitedAccessObject.SETRANGE("Object Type",ESLimitedAccessObject."Object Type"::Table);
      IF ESLimitedAccessObject.FIND('-') THEN
        REPEAT
          ESLimitedAccessObject2 := ESLimitedAccessObject;
          ESLimitedAccessObject2.VALIDATE("Security Table ID",0);
          ESLimitedAccessObject2.MODIFY(TRUE);

          ModifiedRecords := ModifiedRecords + 1;
        UNTIL ESLimitedAccessObject.NEXT = 0;

      HistoryTableSetup.RESET;
      HistoryTableSetup.FIND('-');
      REPEAT
        IF HistoryTableSetup."History Table No." <> 0 THEN BEGIN
          IF NOT ESLimitedAccessObject.GET(
                   ESLimitedAccessObject."Object Type"::Table,
                   HistoryTableSetup."Table No.")
          THEN BEGIN
            ESLimitedAccessObject.INIT;
            ESLimitedAccessObject."Object Type" := ESLimitedAccessObject."Object Type"::Table;
            ESLimitedAccessObject."Object ID" := HistoryTableSetup."Table No.";
            ESLimitedAccessObject.VALIDATE(
              "History Table ID",HistoryTableSetup."History Table No.");
            ESLimitedAccessObject.INSERT(TRUE);

            InsertedRecords := InsertedRecords + 1;
          END ELSE BEGIN
            ESLimitedAccessObject.VALIDATE(
              "History Table ID",HistoryTableSetup."History Table No.");
            ESLimitedAccessObject.MODIFY(TRUE);

            ModifiedRecords := ModifiedRecords + 1;
          END;
        END;

        IF HistoryTableSetup."Security Table No." <> 0 THEN BEGIN
          IF NOT ESLimitedAccessObject.GET(
                   ESLimitedAccessObject."Object Type"::Table,
                   HistoryTableSetup."Table No.")
          THEN BEGIN
            ESLimitedAccessObject.INIT;
            ESLimitedAccessObject."Object Type" := ESLimitedAccessObject."Object Type"::Table;
            ESLimitedAccessObject."Object ID" := HistoryTableSetup."Table No.";
            ESLimitedAccessObject.VALIDATE(
              "Security Table ID",HistoryTableSetup."Security Table No.");
            ESLimitedAccessObject.INSERT(TRUE);

            InsertedRecords := InsertedRecords + 1;
          END ELSE BEGIN
            ESLimitedAccessObject.VALIDATE(
              "Security Table ID",HistoryTableSetup."Security Table No.");
            ESLimitedAccessObject.MODIFY(TRUE);

            ModifiedRecords := ModifiedRecords + 1;
          END;
        END;
      UNTIL HistoryTableSetup.NEXT = 0;

      MESSAGE(Text002,InsertedRecords);

      // ERROR(Text001);
    END;

    BEGIN
    END.
  }
}

