AutoPrint at a specified time

Sure Ashley.

Here’s some generic code from a post I can’t find (I’ve changed it to use the ttResults table that is available in the GetList method of a UBAQ Directive). It sends a standard email. This code won’t email a report, but it shows how you can pull in data from a
UBAQ that could be later used to generate/email a report.

//Test Email
	// Email Notification

    // Initialize Actions
    Func<string, string> GetCompanyAddressAction = (CompanyID) => {

      var Company_Row =
        (from sc in Db.SysCompany.With(LockHint.NoLock)
        where sc.Company == CompanyID
        select new { sc.EmailFromAddr, sc.EmailFromLabel }).FirstOrDefault();

      if (Company_Row != null) {
        return string.Format(@"""{0}"" <{1}>", Company_Row.EmailFromLabel.Trim(), Company_Row.EmailFromAddr.Trim());
      }

      return string.Empty;
    };

    foreach(var ttResults_Row in ttResults) {
      // Initialize Variables
      string EmailTO = "aszoka@myemail.com";
      string EmailCC = "";
      string EmailBCC = "";
      string EmailSubject = "";
      string EmailBody = "";
  
  
      if (ttResults_Row != null)
      {    
		if (ttResults_Row.Calculated_neverBeforeOrdered == 1) {

			EmailSubject += "First Article Required. Part: " + ttResults_Row.OrderDtl_PartNum + " Order: " + ttResults_Row.OrderHed_OrderNum;

		}
          
          EmailBody = "";
          
          if(EmailTO != "") {
            // Send Email
            var mailer = this.GetMailer(async:true);
            var message = new Ice.Mail.SmtpMail();
            message.SetFrom( GetCompanyAddressAction("99999") );
            message.SetTo(EmailTO);
            message.SetCC(EmailCC);
            message.SetBcc(EmailBCC);
            message.SetSubject(EmailSubject);
            message.SetBody(EmailBody);
            message.IsBodyHtml = true;
            mailer.Send(message);
          }
       }
    }

In order for you to email your BAQ report, you’ll need to generate a BAQ report from a BPM. I’ve never had to do this, but there’s a few posts on here related to it. E10 - Print BAQReport from C#

Anyway, you can use some of the above code to load in data from a UBAQ to your UBAQ’s GetList method (Found in Updatable BAQ Directives Maintenance), then use that data to generate/email the reports you need.

What are your BAQ reports that you have to do twice-daily? Does a standard report schedule not work? If the report recipients or the report content isn’t dynamic, there’s probably an easier way to automate it than this.

1 Like