Inspection Processing Entry Report

Hello epicor community, I was wondering is there anyway to print an report for inspection processing after QA/QC have key-in in inspection processing entry.

We use an SSRS Report to create a printable inspection report.

But we are moving towards using ECM Forms instead now.

We did something with a BPM , it automatically builds the email and notifies the user the result along with the attachments the inspectors add.

1 Like

Hi @ridgea do you have any example of your BPM so i can refer if you don’t mind?

@Ziqqie_ringstorm no worries

// Initialize Variables
string EmailTO = "";
string EmailCC = "";
string EmailBCC = "";
string EmailSubject = "";
string EmailBody = "";

// Dictionary to store attachments (filename and stream)
Dictionary<string, Stream> attachments = new Dictionary<string, Stream>();

// Strings to store email addresses
string ResEmail = string.Empty; // Resource Email
string empEmail = string.Empty; // Employee Email

// Get the first row from the 'ttFirstArt' collection
var faiRow = ttFirstArt.FirstOrDefault();
if (faiRow != null)
{
    // Retrieve the 'OpCode' from the 'Db.JobOper' table based on specific conditions
    string opCode = Db.JobOper
        .Where(a => a.Company == callContextClient.CurrentCompany &&
                    a.JobNum == faiRow.JobNum &&
                    a.AssemblySeq == faiRow.AssemblySeq &&
                    a.OprSeq == faiRow.OprSeq)
        .Select(a => a.OpCode)
        .FirstOrDefault();

    // Get the 'FirstArtSvcContract' service to work with 'FirstArt' data
    var svcFAI = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.FirstArtSvcContract>(this.Db);
    if (svcFAI != null)
    {
        // Retrieve data from 'FirstArt' service using the 'SysRowID' from 'faiRow'
        var dsFAI = svcFAI.GetBySysRowID(faiRow.SysRowID);
        var faiResult = dsFAI.FirstArt.Select(r => r).FirstOrDefault();

        if (faiResult != null)
        {
            // Set the 'status' based on a user-defined field 'FAIStatus_c' from 'faiResult'
            string status = faiResult.UDField<System.String>("FAIStatus_c");

            // Set the email targets by fetching email addresses from different tables
            empEmail = (from row in Db.EmpBasic
                        where row.Company == faiRow.Company &&
                              row.DcdUserID == faiResult.EntryPerson
                        select row.EMailAddress)
                       .FirstOrDefault();
            ResEmail = Db.Resource
                .Where(a => a.Company == callContextClient.CurrentCompany && a.ResourceID == faiResult.ResourceID)
                .Select(a => a.EmailAddress_c)
                .FirstOrDefault();

            // Set the email subject with specific information from 'faiRow' and 'faiResult'
            EmailSubject = "[ Alert - First Off: " + status + " Job No/Op: " + faiRow.JobNum + "/" + faiRow.OprSeq.ToString() + "] " + faiResult.JobAsmPartNum + " / " + faiResult.JobAsmDescription;

            // Prepare the email body with specific formatting and data from 'faiRow' and 'faiResult'
            string color = status == "Pass" ? "Green" : "Red";
            string header = @"<h1 style='background-color:" + color + ";'>" + "The following has " + status + "ed first off inspection:" + "</h1>";

            EmailBody += string.Format(header);
            EmailBody += "<body>";
            EmailBody += "<p>";
            EmailBody += string.Format("Job No: " + faiRow.JobNum);
            // ...
            // (Other email body lines)
            // ...
            EmailBody += "</p>";
            EmailBody += "</body>";

            // Fetch attached drawings using the 'DrawingsSvcContract' service and add them to 'attachments' dictionary
            var svcDrg = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.DrawingsSvcContract>(this.Db);
            if (svcDrg != null)
            {
                string whereClauseDrawings = "ForeignSysRowID =  '" + faiResult.SysRowID + "' AND RelatedToFile = 'FirstArt'";
                bool drgPgs;
                var dsDrg = svcDrg.GetRows(whereClauseDrawings, 10, 0, out drgPgs);

                if (dsDrg.Drawings.Count > 0)
                {
                    foreach (var dwg in dsDrg.Drawings.Where(a => a.DocTypeID == "INSPEC"))
                    {
                        try
                        {
                            // Read the file content and create a stream to add to the attachments dictionary
                            var filename = dwg.FileName;
                            byte[] fileContents = File.ReadAllBytes(filename);
                            var stream = new MemoryStream(fileContents);
                            stream.Position = 0;
                            attachments.Add(dwg.DrawDesc, stream);
                        }
                        catch (Exception ex)
                        {
                            // Handle the exception (currently commented out)
                            // throw new BLException(ex.Message);
                        }
                    }
                }
            }

            // Send the email using the 'mailer' and 'message' objects, along with attachments
            var mailer = this.GetMailer(async: true);
            var message = new Ice.Mail.SmtpMail();
            message.SetFrom("");
            message.SetTo(empEmail);
            message.SetCC(ResEmail);
            message.SetSubject(EmailSubject);
            message.SetBody(EmailBody);
            message.IsBodyHtml = true;
            mailer.Send(message, attachments);
        }
    }
}

Thank you @ridgea but are you using epicor on prem or cloud? because I’m using epicor kinetic

@Ziqqie_ringstorm , i am on Prem. Albeit I don’t think it should make a huge difference.

Here is a link to my post on how to create it.

Inspection Report — FINALLY! - ERP 10 - Epicor User Help Forum (epiusers.help)

2 Likes

Thanks @jkane this include the steps on how to create the inspection report?

Hi @ridgea can show me the steps how its done in the BPM cause I’ve never used BPM before

Yes.