Same SO Report being sent

Hi,
I have a loop that sends a SO report to their respective customer email addresses. It works in that they get emails and get a report. However, the same report is sent to every single email address. I’m not sure what I’m doing wrong. It seems correct to me. Any hints would be much appreciated.

To clarify, I’ve been testing on order 67681 but report from order 107584 is being sent to the email. A completely unrelated order gets sent to the email.

var OrderHedTable =
(from Order_Row in Db.OrderHed.With(LockHint.NoLock)
where Order_Row.AutoPrintReady == true
select new { OrderNum = Order_Row.OrderNum, CustNum = Order_Row.CustNum }).ToList();

if (OrderHedTable != null) {

// Loop through all auto-print ready orders
foreach (var row in OrderHedTable) {

  // Find email of customer
  var CustomerRow =
  	(from Customer_Row in Db.Customer.With(LockHint.NoLock)
  	where Customer_Row.LegalName != "" && Customer_Row.CustNum == row.CustNum
  	select Customer_Row).FirstOrDefault();

  if (CustomerRow != null) {

  		// send email
  		var soForm = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderAckSvcContract>(Db);
  		SalesOrderAckTableset soTS = soForm.GetNewParameters();
  		SalesOrderAckParamRow r = soTS.SalesOrderAckParam[0];

  		r.OrderNum = (int)row.OrderNum;
  		r.SysRowID = Guid.Parse("00000000-0000-0000-0000-000000000000");
  		r.AutoAction = "SSRSPrint";
  		r.AgentSchedNum = 0;
  		r.AgentID = "SystemTaskAgent";
  		r.AgentTaskNum = 0;
  		r.RecurringTask = false;
  		r.RptPageSettings = "";
  		r.RptPrinterSettings = "";
  		r.RptVersion = "";
  		r.ReportStyleNum = 2;
  		r.WorkstationID = "";
  		r.TaskNote = "";
  		r.ArchiveCode = 0;
  		r.DateFormat = "m/d/yyyy";
  		r.NumericFormat = ",.";
  		r.AgentCompareString = "";
  		r.ProcessID = "";
  		r.ProcessTaskNum = 0;
  		r.DecimalsGeneral = 0;
  		r.DecimalsCost = 0;
  		r.DecimalsPrice = 0;
  		r.GlbDecimalsGeneral = 0;
  		r.GlbDecimalsCost = 0;
  		r.GlbDecimalsPrice = 0;
  		r.FaxSubject = string.Format("Order: {0} The Sales Ack has been sent to you enjoy reading", row.OrderNum); 
  		r.FaxTo = "";
  		r.FaxNumber = "";
  		r.EMailTo = CustomerRow.LegalName;
  		r.EMailBody = "";
  		r.AttachmentType = "PDF";
  		r.ReportCurrencyCode = "USD";
  		r.ReportCultureCode = "en-US";
  		r.SSRSRenderFormat = "PDF";
  		r.RowMod = "A";

  		soForm.RunDirect(soTS);
  }

  var OrderHed_Row2 = 
  	(from OrderHed_xRow in Db.OrderHed.With(LockHint.NoLock)
  	where OrderHed_xRow.OrderNum == row.OrderNum
  	select OrderHed_xRow).FirstOrDefault();
  if (OrderHed_Row2 != null) {
  	OrderHed_Row2.AutoPrintReady = false;
  }

}
}

My first question is why are you doing it this way? Couldnt you just use the standard auto print from a data directive when auto-print is toggled from false to true?

I was able to get it to work. Turns out I had to remove defaults. We’re doing it this way to send mass emails at a specific time.