Auto Print Setup - Bartender Labels

Hello~!

I am trying to find the best way to do this…

I need a BPM that auto prints a Bartender label when ShipHead.ReadyToInvoice is changed to True.

Depending on the customer/CustID, the label will be unique. Right now we have about five, give or take, but this might grow so something that is easy to add onto or dynamic would be best.

I have mulled over this but I am not sure the easiest, most efficient path. We have someone to code the C# for this, but I need to help guide them.

Thank you.

Right now I have the BPM like this:

Condition → The ttShipHead.ReadyToInvoice field has been changed from any to True
→ Custom Code ??
->Automatically print PackSlip report with selected options with rule

I need it to identify a list of customer IDs (otherwise ignore and don’t follow through) and I need to assign those specific IDs to their corresponding Bartender label.

The reason I go toward custom code is because while it is a few for now, it is going to grow and I need to edit it easily.

I use code similar to this to print labels in a method directive, maybe it can be of help:

    Dictionary<string, string> dict = new Dictionary<string, string>();
    dict.Add("job_num", l.JobNum);
	
	var data = JsonConvert.SerializeObject(new {PrintBTWAction = new {DocumentFile = "PATH_TO_LABEL", Printer = PATH_TO_PRINTER, NamedDataSources = dict}});
    var address = "YOUR_SERVER_IP:5159/api/actions?MessageSeverity=Info";
    
    try {
      WebRequest req = WebRequest.Create(address);
      req.Headers["Content-Type"] = "application/json";
      req.Credentials = CredentialCache.DefaultNetworkCredentials;
      var httpWebRequest = (HttpWebRequest) req;
      httpWebRequest.Method = "POST";
      using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
      {
          streamWriter.Write(data);
      }
      var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
      using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
      {
          var result = streamReader.ReadToEnd();
      }
    } catch (WebException ex) {
      var resp = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
      Epicor.Customization.Bpm.InfoMessage.Publish("Error: " + ex.Message + " - " + resp);
    }

I am setting up a Method Directive to do what I want and will have my guy look at the code to adjust.

Meanwhile, he has this for the Data Directive version:

ChooseLabels.cs (1.3 KB)

The out of the box version of the report style for bartender labels is the GenShip report style, and typically that would be generated from either setting the autoprintready flag on the erp.ShipHead table on a standard data directive (Which I think you got anyway). I don’t think the AutoprintReady field is displayed on the Customer Shipment Entry Screen by default.

My understanding is that this also can be fired from using the standard packing list report and selecting labels or bot from the options.

Looking at your code, and as you have multiple different labels (not sure if it would be practical to change the layout on the fly checking the customer in the data and turning on and off specific fields). That may be an option based on the label template complexity involved, bartender designer is pretty good at that sort of thing.

The other alternative is looking at calling a function that calls the bartender REST API. Here is a link at an example https://www.epiusers.help/t/insights-2024-rest-api-bartender/115692.

Hope that helps

So we switched it up a bit and got rid of the Auto Print widget. This is what we have for our code, but obviously it is not working.

I think part of the issue is having it pull the RDD information in?:

string custID = “”;

if (this.ttShipHead != null && this.ttShipHead.Any())
{
var custNum = this.ttShipHead.FirstOrDefault()?.CustNum;
custID = Convert.ToString(custNum);

}

string label;

switch(custID)
{
case “963A”:
label = “AMAT_Packaging_Label.btw”;
break;
case “1265”:
label = “Bruker_Packaging_Label.btw”;
break;
case “696”:
label = “Philips_Packaging_Label.btw”;
break;
case “1070”:
label = “QD_Packaging_Label.btw”;
break;
case “02CSML”:
label = “Siemens_Packaging_Label.btw”;
break;
default:
label = “Error”;
break;
}

bool report = false;
if(label != “Error”)
{
report = true;
}

if(report = true)
{
try
{
string labelName = label;
string printerName = “\\Alntprint\Admin Xerox PrimeLink C9070”;
string labelFilePath = $@“C:\Bartender Documents{labelName}”;
string printCommand = $@“”“C:\Program Files\Seagull\BarTender 2022\bartend.exe”" " + $@“/F=”“{labelFilePath}”" /PRN=“”{printerName}“” ";

// Execute the print command
var processInfo = new ProcessStartInfo("cmd.exe", $"/C {printCommand}")
{
    CreateNoWindow = true,
    UseShellExecute = false
};

//Ice.Diagnostics.Log.WriteEntry($"Label printed for", label);

}
catch(Exception ex)
{
//Ice.Diagnostics.Log.WriteEntry($“Error printing label: {ex.Message}”);
throw;
}

}
else
{
// Ice.Diagnostics.Log.WriteEntry($“Error choosing label”);

Check where it is failing,. Is it creating the file at all?

Point to note in earlier versions trying to execute the label directly generated the file but with no printer info if I recall, been a while.