Create a codeunit and subscribe to the above event. In this event, you can do like the following:
codeunit 50100 "Replace Reports"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnAfterSubstituteReport', '', false, false)]
local procedure OnAfterSubstituteReport(ReportId: Integer; var NewReportId: Integer)
begin
if ReportId = Report::"Sales Invoice" then
NewReportId := Report::"My New Sales Invoice";
end;
}
In this event you can write the logic you want for changing the report at runtime.