+### Load svcs that are no longer linked (cust_svc has been deleted)
+
+# get list of all svcs for this customer from h_cust_svc
+# could also load svcdb here by joining to part_svc on svcpart,
+# but it would spoil database optimizations on this lookup
+my @svcnumobj = qsearch({
+ 'select' => 'DISTINCT svcnum',
+ 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than } },
+ 'table' => 'h_cust_svc',
+ 'addl_from' => 'JOIN cust_pkg USING (pkgnum)',
+ 'extra_sql' => ' AND custnum = '. $cust_main->custnum,
+});
+
+# now grab those svcs explicitly
+foreach my $svcnum ( map { $_->get('svcnum') } @svcnumobj ) {
+ # can skip the services we already found
+ next if $foundsvcs{$svcnum};
+ # grab any given h_cust_svc record for this svcnum to get svcdb
+ my $svcdbobj = qsearchs({
+ 'select' => 'svcdb',
+ 'hashref' => { svcnum => $svcnum },
+ 'table' => 'h_cust_svc',
+ 'addl_from' => 'JOIN part_svc USING (svcpart)',
+ 'extra_sql' => 'LIMIT 1',
+ });
+ unless ($svcdbobj && $svcdbobj->get('svcdb')) {
+ # don't think this ever happens, but just in case, don't break history page over it
+ warn "Could not load svcdb for svcnum $svcnum";
+ next;
+ }
+ my @items = qsearch({
+ 'table' => "h_".$svcdbobj->get('svcdb'),
+ 'hashref' => { 'history_date' => { op=>'>=', value=>$newer_than },
+ 'svcnum' => $svcnum },
+ });
+ push @history, @items;