MES Customization Help

Hello,

I’m trying to make a modification to MES to where when a job is clock into from a certain department, it automatically launches the End Activity Window after they finish clocking in.

I’ve never done a customization before, so I’m not sure if i’m going about it the right way. below is the script I’m using in script editor, it is launching the window, but it doesn’t seem linked to the job. I’m getting the application error below after I clock in.
image

and then it opens end labor activity, with no information like job number linking it to the job.

// **************************************************
// Custom code for MESMenu
// Created: 3/6/2025 6:28:39 PM
// **************************************************
using System;
using System.Windows.Forms;
using Ice.Lib.Framework;
using Ice.Lib.Customization;
using System.Threading.Tasks;

public class Script
{
private EpiDataView edvLaborDtl;
private bool hasLaunched = false; // Prevents duplicate

public void InitializeCustomCode()
{
    edvLaborDtl = (EpiDataView)oTrans.EpiDataViews["LaborDtl"];

    if (edvLaborDtl != null)
    {
        edvLaborDtl.EpiViewNotification += new EpiViewNotification(LaborDtl_Changed);
    }
}

public void DestroyCustomCode()
{
    if (edvLaborDtl != null)
    {
        edvLaborDtl.EpiViewNotification -= new EpiViewNotification(LaborDtl_Changed);
    }
}

private async void LaborDtl_Changed(EpiDataView view, EpiNotifyArgs args)
{
    if (args.Row > -1 && !hasLaunched) // Ensure it's a valid row
    {
        try
        {
            // Get values
            string opCode = view.dataView[args.Row]["OpCode"].ToString();
            int activeTrans = Convert.ToInt32(view.dataView[args.Row]["ActiveTrans"]);
            string laborType = view.dataView[args.Row]["LaborType"].ToString();

            // Conditionals
            if (opCode.Equals("WC15", StringComparison.OrdinalIgnoreCase) && 
                activeTrans == 1 && 
                laborType.Equals("P", StringComparison.OrdinalIgnoreCase))
            {
                hasLaunched = true; // duplicate trigger check

                // Wait 
                await Task.Delay(1500);

                // launch 
                ProcessCaller.LaunchForm(oTrans, "Erp.UI.EndActivityEntry");

                hasLaunched = false; // Reset flag
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error in LaborDtl_Changed: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            hasLaunched = false; // Reset flag 
        }
    }
}

}

Have you looked at Report Quantity? You can use that to record your production (if you don’t have nonconformance or scrap) without going through the Start Production Activity and End Production Activity.

Doesn’t solve your customization problem, but might eliminate your need to customize.

Edit: Lots of forms require the use of launch form options to pass data into them when you open them. This is one of them.

Why to wait till they finish clocking in?
You can do a check when they start activity. Maybe a BPM → Method Directives → Labor → Update → Pre-Processing; where a row is added, and take EmpId from LaborDtl table and compare with Employee table, fetch the department and throw an error. You will need to use Custom Code widget to achieve this.

Unfortunately it needs to be done through forms, I have already done it via a BPM/Report quantity for a different manner, but this one specific instance is basically just a shortcut to speed up reporting in one department.

This is one of those times that it might be good to step back and assess the problem you are really trying to solve. You’ve determined on your own that you need to customize End Labor Activity. But what led you to that point?

To @Chad_Smith’s point, if you are simply trying to end activity right when you start it, that’s exactly what Report Quantity does.

I tend to agree with @dr_dan. I can’t tell you how many times I have seen a company @$&?! themselves trying to maintain the same process instead of concentrating on the business problem.

I am trying to open the end activity report, as the company still wants them to be able to enter the information such as quantity/scrap/DMR. I would much rather have it automatically close the job out (and I made a version that did just that) but it was shot down, so this was the compromise, all I’m looking for is for it to open the end activity window after they have clocked into the job automatically.

Feel free to add votes to this: KIN-I-4590 Able to report scrap and non-conformity in report quantity

Off to go add this to the Friday post.

Take a look here for some info on using lfo when launching forms.