Auto Printing - Mtl Labels

I was just wondering if somebody has done something similar for auto printing mtl tags when doing a labour transaction.

Basically I’ve ran a trace log and the report parameter “ItemTags” is the only report parameter I seem to be having a problem with. What I am trying to achieve is to be able to replicate the output 5.001~1.001 like shown below the main variant being the division of the Transaction Qty by the parts per container. But unfortunately no luck so far as I get a parse error :frowning: - Works fine for 1 offs thought :slight_smile: .

Hate to open an old thread but have you ever found a way to do this? I’m having a problem getting this to work unless I hard code a number in the itemTags parameter

No worries.

I ended up splitting this across pre and post method directives.

List<string> errorList = new List<string>();

var lbrDtl = ds.LaborDtl.Where(a => a.RowMod =="U").Select(a => a).FirstOrDefault();
if (lbrDtl != null && callContextClient.AssemblyName == "App.EndActivityEntry.EndActForm")
{
    // Check the Operation Mater to see if the OpCode for the Labor Transctions required labels.
    bool labelsRequired = Db.OpMaster.Where(a => a.Company == callContextClient.CurrentCompany && a.OpCode == lbrDtl.OpCode).Select(a => a.LabelsRequired_c).FirstOrDefault();
    
    if (labelsRequired && lbrDtl.LaborQty > 0)
    {  
        //Get no of labels required
        int labelsCount = lbrDtl.UDField<int>("NoOfLabels_c"); 
        
        if (labelsCount == 0) throw new BLException("It is madatory to for this operation to have labels printed (traceability purposes)");
    
        if (labelsCount > lbrDtl.LaborQty) // Number of labels > Labor Qty 
        {
        errorList.Add("The number of labels (" + labelsCount.ToString() + ") requested can't be greater than the Completed Qty (" + lbrDtl.LaborQty.ToString() + ")" + Environment.NewLine +  Environment.NewLine + "Min number of labels = 1" +  Environment.NewLine + "Max number of labels = " + lbrDtl.LaborQty.ToString()); 
        }
   
        if (lbrDtl.LaborQty/labelsCount % 1 != 0) // Whole number ?
        {
        decimal divResult = (decimal)lbrDtl.LaborQty/(decimal)labelsCount;
        errorList.Add("Labor Qty: (" + lbrDtl.LaborQty.ToString() + ") divided by no of labels req'd (" + labelsCount.ToString() + ") = " + divResult.ToString("n2") + " parts per label" + Environment.NewLine +  Environment.NewLine + "Please re-enter the number of labels that reuslts in an equal division!");
        }
    
    }   
  
}

if (errorList.Count > 0)
{
string message = String.Join(Environment.NewLine, errorList.ToArray());
throw new BLException(message);
}

Then in the Post Processing, a quick conditon to its been enabled from Pre Processing directive
then custom code block

var lbrDtl = ds.LaborDtl.Select(a => a).FirstOrDefault();
if (lbrDtl != null && callContextClient.AssemblyName == "App.EndActivityEntry.EndActForm")
{
    
    //Get Printer ID lnked to Resource -> this can be linked to the resource ID in Resource Printer Maintance -> Be sure to mark the printer as the default printer. 
    var defaultPrinter = (from pkg in Db.PkgControlResourcePrinter
    join prnt in Db.SysPrinter on new {pkg.Company, pkg.PrinterID} equals new {prnt.Company, prnt.PrinterID}    
    where prnt.Company == callContextClient.CurrentCompany && pkg.ResourceID == lbrDtl.ResourceID && pkg.IsDefaultPrinter == true select new {pkg.ResourceID,prnt.PrinterID,prnt.Description,prnt.NetworkPath}).FirstOrDefault();
    
    string printerName = defaultPrinter.NetworkPath;
    string printerSettings = @"PrinterName=""" + defaultPrinter.NetworkPath + @""",Copies=1,Collate=True,Duplex=Default,FromPage=1,ToPage=0";

    //throw new Ice.BLException( + Environment.NewLine + printerSettings2);
    
    // No of labels Required
    int labelsCount = lbrDtl.UDField<int>("NoOfLabels_c");  
  
    // Check labels Required is greater than zero
    if (labelsCount > 0)
    {
    
        // Get MtlTags Svc 
        var svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.MtlTagsSvcContract>(this.Db);
        if (svc == null) throw new BLException("Could not render service Erp.Contracts.MtlTagsSvcContract.");
        {     
        
            // Grab Job Assembly Details
            var ja = Db.JobAsmbl.Where(a => a.Company == callContextClient.CurrentCompany && a.JobNum == lbrDtl.JobNum && a.AssemblySeq == lbrDtl.AssemblySeq).FirstOrDefault();              
                      
            try
            { 
            
            // Qty per Tag
            decimal qtyPer =  lbrDtl.LaborQty/labelsCount;
                   
            //Set Up Paramters for row inserssion into Tableset 
            var reportParamTS = new Erp.Tablesets.MtlTagsTableset();
            var reportParamRow = new Erp.Tablesets.MtlTagsParamRow();
            reportParamTS.MtlTagsParam.Add(reportParamRow);
            
            // Tag Qty Parameters
            reportParamRow.TagFormat = Convert.ToString("MFG-OPR");
            reportParamRow.TotalQty = Decimal.ToInt32(lbrDtl.LaborQty); // Transaction Qty
            reportParamRow.TagQty = labelsCount; // Lbr Qty / No Of Tags
            reportParamRow.QtyPer = qtyPer;
                    
            // Paramters to push into Mtl Tags  
            reportParamRow.PartNum = (ja.PartNum);
            reportParamRow.Revision = (ja.RevisionNum);
            reportParamRow.PartDesc = (ja.Description);
            reportParamRow.UnitOfMeasure = lbrDtl.ResourceID;
            reportParamRow.JobNum = lbrDtl.JobNum;
            reportParamRow.AssemblySeq = lbrDtl.NextAssemblySeq;
            reportParamRow.OprSeq = lbrDtl.NextOprSeq;
            reportParamRow.PONum = Convert.ToInt32("0");
            reportParamRow.POLine = Convert.ToInt32("0");
            reportParamRow.PORel = Convert.ToInt32("0");
            reportParamRow.VendorNum = Convert.ToInt32("0");
            reportParamRow.RefAssemblySeq = Convert.ToInt32("0");
            reportParamRow.RefMtlSeq = Convert.ToInt32("0");
            reportParamRow.NonConfTranID = Convert.ToInt32("0");
            reportParamRow.Comment = lbrDtl.LaborNote;
            reportParamRow.ItemTags = (qtyPer.ToString("G") + "" + "`" + labelsCount.ToString("G"));
            reportParamRow.JobSeqType = Convert.ToString("M");
            reportParamRow.BarCodes = Convert.ToBoolean("True");
            reportParamRow.PrintReportParameters = Convert.ToBoolean("False");
            reportParamRow.SSRSEnableRouting = Convert.ToBoolean("False");
            reportParamRow.ArchiveCode = Convert.ToInt32("0");             
            reportParamRow.AutoAction =  "AUTOPRT" ;
            reportParamRow.ReportStyleNum =  lbrDtl.LaborType == "S" ? 1003 : 1002;
            reportParamRow.WorkstationID = Session.TaskClientID; 
            reportParamRow.TaskNote = "Auto Print MtlTags (BPM) - Labor Tran ID: " + lbrDtl.LaborDtlSeq.ToString();
              
            string pageSettings =  "Color=False,Landscape=True,Margins=[Left=0 Right=0 Top=0 Bottom=0],PaperSize=[Kind=\"PrcEnvelopeNumber1\" PaperName=\"PrcEnvelopeNumber1\" Height=200 Width=400],PaperSource=[SourceName=\"AutomaticFeed\" Kind=\"AutomaticFeed\"],PrinterResolution=[Kind=\"Custom\" X=600 Y=600]";
                  
            reportParamRow.PrinterName = printerName;
            reportParamRow.RptPrinterSettings = printerSettings;
            reportParamRow.RptPageSettings = pageSettings;
            
            svc.SubmitToAgent(reportParamTS,"SystemTaskAgent",0,0,"Erp.UIRpt.MtlTags");
       
            PublishInfoMessage(labelsCount.ToString() + " off label(s) have been successly printed !" + Environment.NewLine + "Please collect your label from: " + defaultPrinter.Description + " and ensure the part is identified with the label.", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, string.Empty, string.Empty);
            }
            
            catch (Exception ex)
            {
            PublishInfoMessage(ex.Message.ToString() , Ice.Common.BusinessObjectMessageType.Error, Ice.Bpm.InfoMessageDisplayMode.Individual, string.Empty, string.Empty);
            } 
    
        }
    }
    
}

I got it. Thank you your code helped. I got it to run through the standard Data directive and what I was missing is that a string with 1.000000 does not parse to 1 by doing int.tryparse you have to first do double.tryparse then int.tryparse. The Code of Decimal qtyPer then in the ItemTags converting that to string was what made me think about my conversion. Thank you So much.

No worries you’re welcome.

My experience with using the widget stuff for auto printing is scalability.

Deploying it using the c# editor provides much more flexibility and I won’t have to worry about having to add a printer manually to the standard data directive each time I need to link to an additional printer as this is mastered by Resource printer for this instance. So simply a matter of point and go.

Just food for thought ….