Filling a textbox field from C# variable

I would like to fill a few fields on the Start Production Activity form from variables.

This is how I have I have my code set up so far. I have a timer built in so the field won’t fill in until the form is open (not sure if this is necessary, but I thought that was why the field wasn’t getting filled in. I may be able to do this all in StartProdForm_Load).

Once I get the job field to work, I would like to also fill the assembly and operation fields, which are combo boxes.

public class Script
{
    EpiTextBox txtJob;

    public void InitializeCustomCode()
    {
        txtJob = (EpiTextBox)csm. GetNativeControlReference("2233c0f7-d359-4959-8387-2a9b8395149b");
    }

    Timer timer1 = new Timer();

    public string job
    {
        get;
        set;
    }
    
// Pull barcode in from MESMenu
    public void StartProdForm_Load(object sender, EventArgs e)
    {
        if(StartProdForm.LaunchFormOptions != null)
        {
            object barcodeObj = StartProdForm.LaunchFormOptions.ContextValue;
            // Convert barcode (object to string)
            string barcode = barcodeObj.ToString();
            // Split barcode into parts
            var items = barcode.Split('-');
            string job = items[1];
            string asm = items[2];
            string opr = items[3];
            this.timer1.Interval = 5000;
            timer1.Start();
        }
    }
    
    public void timer1_Tick(object sender, EventArgs e)
    {
        timer1.Stop();
        // Fill fields
        txtJob.Text += job;
    }
}
1 Like

Don’t fill in the TextBox use the DataViews (this will trigger all the appropriate events for you)

var startDV= oTrans.Factory("Start");
startDV.dataView[startDV.Row].BeginEdit();
startDV.dataView[startDV.Row]["JobNum"]=jobNum;
startDV.dataView[startDV.Row].EndEdit();
3 Likes

It still isn’t populating the field. I removed the timer and simplified the code a bit.

public void StartProdForm_Load(object sender, EventArgs e)
{
    if(StartProdForm.LaunchFormOptions != null)
    {
        object barcodeObj = StartProdForm.LaunchFormOptions.ContextValue;
        // Convert barcode (object to string)
        string barcode = barcodeObj.ToString();
        // Split barcode into parts
        var items = barcode.Split('-');
        string job = items[1];
        string asm = items[2];
        string opr = items[3];
        // Fill fields
        var startDV = oTrans.Factory("Start");
        startDV.dataView[startDV.Row].BeginEdit();
        startDV.dataView[startDV.Row]["JobNum"]=job;
        startDV.dataView[startDV.Row].EndEdit();
    }
}

Can’t do it on form load you don’t yet have a Row on the dataView. You’ll need that timer. (or another event)

It didn’t work with the timer as well…I don’t love the idea of a timer because if the form takes too long to load then it might not enter the data, but the timer can’t be too long. Is there an event that confirms that the form has been loaded?

Yeah timers are awful. Why are you passing this data via the LFO? What’s the end goal? to SCan something in the Main MES Menu and have it automatically start activity?

Yes, I would like to scan a barcode at the MES menu, have it open up Start Activity, and parse the job number, assembly, and operation into the fields and clock the employee onto the job.

Do it on Start (DataView) NotifyEvent. You’ll need some flags to know that you’ve already done it.

I’m not quite sure how to go about that. I tried creating another method called StartProdForm_Start where the filling of fields would happen. No luck. I am not sure what you mean by NotifyEvent?

Add a Notify event to the Start DAta View. (Using the wizard)

I added an EpiViewNotification using the Form Event Wizard with the “Start” View.

I moved the startDV code lines inside as shown.

public void edvStart_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
{
	// ** Argument Properties and Uses **
	// view.dataView[args.Row]["FieldName"]
	// args.Row, args.Column, args.Sender, args.NotifyType
	// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
	if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))
	{
		if ((args.Row > -1))
		{
			// Fill fields
			var startDV = oTrans.Factory("Start");
			startDV.dataView[startDV.Row].BeginEdit();
			startDV.dataView[startDV.Row]["JobNum"]=job;
			startDV.dataView[startDV.Row].EndEdit();
		}
	}
}

Now I am getting the “Object reference not set to an instance of an object.” error when I try to scan.

Change it from AddRow to Initialize

Same error…

Maybe the details will help?

Application Error

Exception caught in: Erp.UI.StartProductionActivityEntry

Error Detail 
============
Message: Object reference not set to an instance of an object.
Program: Erp.UI.StartProductionActivityEntry.dll
Method: LaborDtl_ColumnChanging

Client Stack Trace 
==================
at Erp.UI.App.StartProductionActivityEntry.StartProdTransaction.LaborDtl_ColumnChanging(Object sender, 
DataColumnChangeEventArgs e)
at System.Data.DataTable.OnColumnChanging(DataColumnChangeEventArgs e)
at Erp.BO.LaborDataSet.LaborDtlDataTable.OnColumnChanging(DataColumnChangeEventArgs e)
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value)
at System.Data.DataRowView.set_Item(String property, Object value)
at Script.edvStart_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
at Ice.Lib.Framework.EpiViewNotification.Invoke(EpiDataView view, EpiNotifyArgs args)
at Ice.Lib.Framework.EpiDataView.OnEpiViewNotification(EpiNotifyArgs e)
at Ice.Lib.Framework.EpiDataView.Notify(EpiNotifyArgs args)
at Erp.UI.App.StartProductionActivityEntry.StartProdTransaction.StartActivity(String hed)

So something isn’t initialized yet in the LaborDtl records… hmnmm

notlistening

A couple questions. Are you passing values into lfo like lfo.ValueIn = “my-values”;
And calling the form passing the lfo like:
ProcessCaller.LaunchForm(this, “Epicor.Mfg.UI.EndActivityEntry”, launchObject);

Have you tested to ensure that your lfo has the values on the receiving form:
object barcodeObj = StartProdForm.LaunchFormOptions.ContextValue;
MessageBox.Show(barcodeObj.ToString());

I assume that “Start” is a valid EpiDataView on that form (in object explorer > data):
var startDV = oTrans.Factory(“Start”);

Yes start is a valid data view the issue is that he is firing this before all the stuff is loaded in the screen.
@fredmeissner you may have to resort to that timer… or just move all the logic to the main MES form.
We just did a project where they wanted to minimize the clicks on MES.
So we had the shortcut launch the custom form and do all the work directly on it.

This is like the holy grail for barcode nerds. No one has been able to figure this out that I have seen so far. I hope you do so I can steal it. Hahaha!

LoL @Banderson I’ve done it however not by launching Start Activity form, just put the code in the MES menu itself. It was a pretty cool customization but it took a lot of code

ok correction, no mortal on the E-10 help forum has figured out how to do it…(I still want to steal it…)

@fredmeissner, @Banderson just did this on Form_Load works great… Give it a shot

private void StartProdForm_Load(object sender, EventArgs args)
  {
  	// Add Event Handler Code
  	
  	var view = ((EpiDataView)(this.oTrans.EpiDataViews["Start"]));
  	if(view.Row>=0)
  	{
  		view.dataView[view.Row].BeginEdit();
  		view.dataView[view.Row]["JobNum"]= "2029";
  		view.dataView[view.Row].EndEdit();
  		
  		view.dataView[view.Row].BeginEdit();
  		view.dataView[view.Row]["AssemblySeq"]=0;
  		view.dataView[view.Row].EndEdit();

  		view.dataView[view.Row].BeginEdit();
  		view.dataView[view.Row]["OprSeq"]=30;
  		view.dataView[view.Row].EndEdit();
  	}
  }

Obviously you’d need to pass in the hard coded values in the LFO. But it works just fine

2 Likes