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);
Answers