Auto Setting Fields in Application Studio

How do I turn the following custom code into something that works inside of application studio? I have a custom field on my start production activity MES screen. I scan the job traveler barcode into this field and it parses out the data into the jobnum, assembly num and opseq fields and then presses the OK button. Any help would be very appreciated!

private void StartProdForm_Load(object sender, EventArgs args)
{
txt_BarcodeScan.Select();
}

private void txt_BarcodeScan_Leave(object sender, System.EventArgs args)
{
    try
    {
        if (txt_BarcodeScan.Text != "")
        {
            string ScanX;
            ScanX = txt_BarcodeScan.Text;
            txt_BarcodeScan.Text = "";
			char[] splitchar = {'-'};
            string[] ParsedScan = null;
			ParsedScan = ScanX.Split(splitchar);
            int CountX = 0;

            foreach (var s in ParsedScan)
                CountX = CountX + 1;

            EpiButton OKButton = (EpiButton)csm.GetNativeControlReference("025fc115-fee3-4973-946e-ba209189d62e");

            if (CountX == 3)
            {
				System.Data.DataRow edvStartRow = edvStart.CurrentDataRow;

                edvStartRow.BeginEdit();
                edvStartRow["JobNum"] = ParsedScan[0];
                edvStartRow["AssemblySeq"] = ParsedScan[1];
				edvStartRow["OprSeq"] = ParsedScan[2];
                edvStartRow.EndEdit();

                oTrans.NotifyAll();

                OKButton.PerformClick();
            }
        }
    }
    catch
    {
    }		
}

}

1 Like

You might have to put your split and count code into a function (unless someone can show us how to split in an App Studio event), then create an event that triggers on OnBlur of your text box, call that function, parse the response into your data row, then call event-next for the OK button event

2 Likes

@jwphillips in this case do you create a function by just adding the function widget and then adding the code? or do i use function maintenance? or is it the same thing?

Yeah, you would create a simple function in Function Maintenance, then call it using the function widget

How do you parse out the info into the correct data rows? What widget do you use for that?

System.Data.DataRow edvStartRow = edvStart.CurrentDataRow;

            edvStartRow.BeginEdit();
            edvStartRow["JobNum"] = ParsedScan[0];
            edvStartRow["AssemblySeq"] = ParsedScan[1];
			edvStartRow["OprSeq"] = ParsedScan[2];
            edvStartRow.EndEdit();

I’m not function expert but I’m thinking you would trigger the function and send the full raw data (JobNum-AsmSeq-OprSeq) then the function splits the data and returns three data fields: JobNum, AsmSeq, OprSeq. Which you assign to the form’s dataview fields.

2 Likes

I (except at insights) dont work with functions so all of this is new to me.

I hear you, I’m pretty new to them too as we’re still working on our Kinetic UI conversions from Classic. I’m starting to draft up a function we’ll need for Order Entry for outside-sales commissions we have in Classic UI.

Is anyone going to be at the WI users group on October 10th that would be willing to help me out a little bit?

Like @Randy said, you’ll have one request parameter - your whole string.

Then you’ll have your three parsed properties as separate output parameters (plus maybe an error message or something to indicate a failed parse) - where I work, we like to give them prefixes for clarity: “ip” for input and “op” for output

Then to set the response values in App Studio, you’ll use a row-update widget after the function call to set your row values to "{actionResult.opJobNum}", etc.

1 Like

So, instead of this code:

You would simply set your output variables to those values. For example:

opJobNum = ParsedScan[0];
opAssemblySeq = ParsedScan[1];
opOprSeq = ParsedScan[2];
1 Like

This is my first function so you are going to have to bear with me. Thanks for the help by the way!

1 Like