Write to CSV with button. Used for Bartender

Found some RuntimeBroker permission errors and added the necessary permissions. I will run the ping for a while too to see if anything shows as dropped.

Hey @Chris_Conn,
I followed the direction here and it works awesome in the basic sense.
What I tried to do and it didnā€™t work is, I did a group by Job Number.

I then highlighted the rows in a job and clicked the button, it didnā€™t populate the pop-up screen at all.
When I donā€™t group anything it works fine.

Is there something I am missing?

It wonā€™t work when you group by anything, unfortunately. It doesnā€™t know how to grab the job number from the grid.

That is unfortunate but I can live with that.
Thank you for the quick answer @Banderson, I appreciate it.

Shawn

Itā€™s just a matter of writing the code to handle that situation. Perfectly do-able

It would be nice if it worked.

How would that work? When you group, did it change the GUID ID?

Or is there something else happening that needs to be monitored?

You have write code that reads and understands the grouping bands. Unfortunately, there isnā€™t a quick snippet I can give to do that.

No problem, just a wishlist kind of thing.
I will make sure they know it won;t work like that and not give them the option.

Thank you for your hard work.

Shawn

My pleasure. If youā€™re able and willing, here is some relevant info.

I changed the title of this post to be something more useful.

1 Like

We are on epicor E10 (10.2.100) and I am having some issues with the MFK-STK label printing. I would like to use a dashboard to facilitate label printing, but I am unable to add a button to a dashboard. How did you add a button to your example? I do have customization permissions and have done some other customization already.

you use the toolbox to add a button. Here is a link to where it is in epic web (you will need access to epic web to see it.) Read through this first and let us know if you have questions after you get through it.

https://epicweb.epicor.com/Education/OnlineHelpFeatureSummary/Epicor%20ERP%2010/10.2.100/Help/enu/Standard/Custom_Basic/TheToolbox.html

1 Like

Bill - make sure you know whether the dashboard you wish to customize is run-time one, or an assembly one.

1 Like

Iā€™m not using bartender for the label printing, but another software.

Iā€™m able to call my print job succesfully, but Iā€™m not having any luck writing the data that I need to a .csv file.

Can anyone point me in the correct direction?

Here is what Iā€™m attempting on a button click event:

private void btnIE_MouseDown(object sender, System.Windows.Forms.MouseEventArgs args)
{
// ** Place Event Handling Code Here **

string pn = ā€œPartNumberLblā€;
string desc = ā€œPartDescā€;
string label = string.Format(ā€œC:\ODBC\LabelWIP.csvā€, new object[0]);

this.MakeLabelData(pn, desc, label);

Here is the ā€œMakeLabelDataā€

private void MakeLabelData (string pn, string desc, string label)
{
this.datas = string.Format(ā€œ"{0}","{1}"ā€, new object
{
pn,
desc
});
}

The code compiles, but doesnā€™t seem to write to the .csv (This printer does not use headers, and just needs to overwrite the data each time.)

Edit: This button wonā€™t be retrieving data from a BAQ, but probably text box values, or something of the sort. I think I can get that working once Iā€™m able to pass the values to the .csv

So this is how I am writing to the CSV. I am using a grid, but you can just change the grid stuff to the text box.

This line of code it the one that is actually writing to the CSV file. Source is a variable created earlier in the code. I wonā€™t pretend to know what the best way to do this is, I have to give @Chris_Conn that credit, but this is what works for us.

System.IO.File.WriteAllLines(to,source);

	private void PrintClick(object sender, EventArgs e)
	{
		string to = "\\\\network location\\clicktext.txt";
                string[] source = {""};


		myCSV = ""; //make sure our CSV is empty
			addDataToCSV("\"pn\","); //add the header information here. This can be done in one line or in many like is shown
			addDataToCSV("\"desc\"");
		foreach(var row in LabelGrid.Rows)   //.the var row now represents the current row as we iterate
		{
		   if(row.Selected)// for only selected rows
		   {

			addDataToCSV(Environment.NewLine);//this adds a carriage return to add this to the next line
		    addDataToCSV("\""+row.Cells["Part_PartNum"].Value.ToString()+"\","); //this adds the data with a comma after it. The comma is needed for each record except the last on a line  
		    addDataToCSV("\""+row.Cells["Part_PartDescription"].Value.ToString()+"\""); //this is the last record on the line. It doesn't need a comma becuase there will be a carriage return before the next line
		   }
		}
	
		MessageBox.Show("CSV: " + myCSV);
		source[0] = myCSV;
		System.IO.File.WriteAllLines(to,source);
        
	}

		private void addDataToCSV(string datastring)
        {
            myCSV += datastring ;
        }
1 Like

I noticed that just as I had responded,

so I can write a single value to the csv using something like this:

  // ** Place Event Handling Code Here **

string pn = ā€œPartNumberLblā€;
string desc = ā€œPartDescā€;
string label = string.Format(ā€œC:\ODBC\LabelWIP.csvā€, new object[0]);

this.MakeLabelData(label, pn, desc);

System.IO.File.WriteAllText(label, pn);

But if i try to write the ā€œdatasā€ constructed, it writes blank data. (Even using a message box displays no data.)

private void MakeLabelData (string pn, string desc, string label)
{
this.datas = string.Format(ā€œ"{0}","{1}"ā€, new object
{
pn,
desc
});
}

Edit:

I think I have it working correctly now, let me do a test label or two.

:slight_smile:

I want to do a similar thing (export to .CSV for Bartender) but I am not doing it in a dashboard like you did here. I want to do it from Customer Shipment Entry.

I see how the code here can create the .CSV file for me, but how do I get it to export data from the ShipHead/ShipDtl tables of the current record into the .CSV? The examples here are to export data from a dashboard grid which I do not have in Shipment Entry.

Youā€™ll have to go find some examples for how you would work with data in the data view. Once you figure out how to get that, you can drop it into the CSV format as shown above.

This is an example for a dataview in a UD screen, but you have a dataview for every screen. You can use the object explorer to find the info for whatā€™s in the dataview on the screen.