Get ToTable Value (CopyData tool)

tompynationtompynation Member Posts: 398
hi,

I'm trying to modify this copydata function (Comes from the Copydata tool) so that it put a range on the Items in the "From Company". This works fine

But then i need another check so that it should not modify item records in the "To Company" when the value for the
Vendor No. is not equal to '1' in the "To Company"... But this is not working
Template.GET(CurrentTemplateName);

Template.TESTFIELD("From Company");
Template.TESTFIELD("To Company");
IF Template."From Company" = Template."To Company" THEN
  ERROR(Text003);

Window.OPEN(Text004);

Table.SETCURRENTKEY(Order);
Table.SETRANGE("Template Name",CurrentTemplateName);
Table.FIND('-');

NumOfTables := Table.COUNT;

REPEAT
  Table.CALCFIELDS(Name);
  Window.UPDATE(1,STRSUBSTNO('%1 - %2',Table."Table No.",Table.Name));

  Window.UPDATE(3,ROUND((CurrTable / NumOfTables) * 10000,1));
  CurrTable := CurrTable + 1; // After update else total progress bar will be 100% while copying last data.

  IF NOT (Table."Skip if Equal Num. of Records" AND
    (GetNumOfRecs(Template."From Company",Table."Table No.") = GetNumOfRecs(Template."To Company",Table."Table No."))) THEN BEGIN

    Field.SETRANGE("Template Name",Table."Template Name");
    Field.SETRANGE("Table No.",Table."Table No.");
    IF Field.FIND('-') THEN BEGIN
      FromTable.OPEN(Table."Table No.",FALSE,Template."From Company");
      ToTable.OPEN(Table."Table No.",FALSE,Template."To Company");

      // TP - 310309
      // Indien Item synchronisatie, Filter op veld "Synchronize item (id: 50002)"
      IF CurrentTemplateName = 'ITEM' THEN BEGIN
        lv_fieldRef := FromTable.FIELD(50002);
        lv_fieldRef.SETRANGE(TRUE);
      END;
      // TP - 310309

      IF FromTable.FIND('-') THEN BEGIN
        NumOfRecs := FromTable.COUNT;
        CurrRec := 0;
        REPEAT
          CurrRec := CurrRec + 1;
          Window.UPDATE(2,ROUND((CurrRec / NumOfRecs) * 10000,1));

          Field.FIND('-');  
          REPEAT
            FromField := FromTable.FIELD(Field."Field No.");
            ToField := ToTable.FIELD(Field."Field No.");

            IF Field."Validate Field" THEN
              ToField.VALIDATE(FromField.VALUE)
            ELSE
             ToField.VALUE := FromField.VALUE;
          UNTIL Field.NEXT = 0;

          ToTable2 := ToTable.DUPLICATE;
          IF ToTable2.FIND THEN BEGIN
            // TP - 310309
            // Controleren of in SD de standaardLeverancier DD is:
            // ja = synchroniserern, nee = overslaan;
            IF CurrentTemplateName = 'ITEM' THEN BEGIN
               lv_ToFieldVendor := FromTable.FIELD(31);
               IF FORMAT(lv_ToFieldVendor) <> '1' THEN BEGIN
                 lv_NumOfRecsNotDD := lv_NumOfRecsNotDD + 1;
                 Window.UPDATE(6,lv_NumOfRecsNotDD);
                 lv_BoolNotDD := TRUE;
               END;
            END;
          IF NOT (lv_BoolNotDD) THEN BEGIN
              CASE Table."Exist Action" OF
                Table."Exist Action"::Modify :
                  BEGIN
                    ToTable.MODIFY(Table."Validate OnModify Trigger");
                    ChangeLogMgt.LogModification(ToTable,ToTable2);
                    NumOfRecsModified := NumOfRecsModified + 1;
                    Window.UPDATE(4,NumOfRecsModified);
                  END;
                ELSE BEGIN
                  NumOfRecsSkipped := NumOfRecsSkipped + 1;
                  Window.UPDATE(5,NumOfRecsSkipped);
                END;
              END;
           END;
          END ELSE BEGIN
            ToTable.INSERT(Table."Validate OnInsert Trigger");
            ChangeLogMgt.LogInsertion(ToTable);
            NumOfRecsCreated := NumOfRecsCreated + 1;
            Window.UPDATE(3,NumOfRecsCreated);
          END;
        UNTIL FromTable.NEXT = 0;
      END;
    END;
    IF Template."Commit After Table Copy" THEN
      COMMIT;
  END ELSE BEGIN
    NumOfRecsSkipped := NumOfRecsSkipped + GetNumOfRecs(Template."From Company",Table."Table No.");
    Window.UPDATE(6,NumOfRecsSkipped);
  END;
UNTIL Table.NEXT = 0;

MESSAGE(Text005,Template."From Company",Template."To Company",NumOfRecsCreated,NumOfRecsModified,NumOfRecsSkipped,
lv_NumOfRecsNotDD);

How could i read the (Original) Value of the "Vendor No." field in the "To Company"

Answers

Sign In or Register to comment.