Form Event Wizard to set a default field value

We are setting up label printing on our shop floor. I’ve made the labels and am using the Print Tags function during End Activity to print.
image

Everything is working except we want to set the Quantity Per Container value to default at 1 but still allow users to change it when needed. It currently defaults to whatever completed quantity is entered. This means we only get 1 label for all the parts instead of 5 labels for 5 parts and so on.
image
I am attempting to set a default value for this following this topic.

But I am getting compile errors.
The field I want to customize is ReportParam.QtyPer.


I am using the Form Event Wizard and choosing EpiViewNotification (per the above topic) and ReportParam.

However when I try compiling the code I get an error that QtyPer field doesn’t exist.
image
What step am I missing here?

Looks like the error is related to that if statement before you BeginEdit (Convert.ToInt32(QtyPer.Value) > 1).

If you change QtyPer.Value to view.dataView[view.Row][“QtyPer”] that should fix it.

Also I think you will want to use the “NotifyType.Initialize” instead of “NotifyType.AddRow”
in the first if statement in the EpiViewNotification:

image

That worked. Thanks. I also changed the NotifyType to Initialize.
Everything is working as we need it to. Code is my nemesis.
Thanks again.

1 Like

I was preparing to roll this out today and I discovered that, while the QtyPer field does default to 1 it does not give me the option to change it to any other number if/when needed.
I want the field to default to 1 but if needed we can change it to another number as when we want 1 label for a container of 50 parts.
Any idea how to do that?

That EpiTransaction.NotifyType.Initialize is probably causing the issue, must be firing multiple times. After closer inspection,I actually used the NotifyType.AddRow in the customization I’ve done this in, so you could try that. Since the dataset you are using is for the report parameters though, I’m not sure if the NotifyType.AddRow would work in this scenario or not.

Alternatively, there should be a way to force your current event to only fire once. You could create a boolean variable that gets set after the epiDataViewNotification fires once, then check for that variable before it fires again.

Or you could try moving the code into a form load event.

Have you tried a BPM? This seems like something that should be set there.

image

I thought this would be a great idea but after trying it several ways I can’t get a BPM to work. When I trigger from GetDefaults nothing happens. Running a trace I don’t see any unique to this form that I could use. All the methods seem generic to all print form windows.

Changing the NotifyType to Addrow doesn’t work. The QtyPer field doesn’t default to 1. I tried moving the code to form load event but that doesn’t give me the the ReportParam selection that I need. I don’t know how to create a boolean variable and set it up like you described.
For now the users are printing labels based on what quantity they put in the End Activity screen. If they only want 1 label for a bin of 20 parts they enter 1, print the label, closed the print tag screen and change the number to 20 then click OK.
Thanks for the help. We’ll re-visit this if it becomes a problem.

I could probably come up with something more elegant if more of my brain cells worked, but move your code back to initialize

//Quick & Dirty!
bool fired = false;   //<-- this should really go near the top of your Script class, but here will work
private void edvReportParam_EpiViewNotification(EpiDataView view, EpiNotifyArgs)
{
   if(args.Row > -1)
   {
        if(!fired) //notice !  -> This says if NOT fired is true
        {
            fired = true; //Now it won't fire again
            //put your other if statement and your row code here
        }
    }

<snip>

}
1 Like

Thanks. That is working, sort of. It is defaulting back to whatever quanty is entered instead of defaulting to 1 but it is letting me change the number. My goal is to default to 1 when the page loads but allow the user to change the number.
I also had to remove the in the code.
Here’s my code now.

bool fired = false;   //<-- this should really go near the top of your Script class, but here will work
private void edvReportParam_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
{
   if(args.Row > -1)
     {
        if(!fired) //notice !  -> This says if NOT fired is true
          {
            fired = true; //Now it won't fire again
            //put your other if statement and your row code here
		{
		// ** 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.Initialize))
			{
			if ((args.Row > -1))
				{
				if (Convert.ToInt32(view.dataView[view.Row]["QtyPer"]) > 1)
					{
					view.dataView[view.Row].BeginEdit();
					view.dataView[view.Row]["QtyPer"]=1;
					view.dataView[view.Row].EndEdit();
					}
				}
			}

        	}
    	  }


    }
} ```
bool fired = false;   //<-- this should really go near the top of your Script class, but here will work
private void edvReportParam_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
{
	if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
	{
		if (args.Row > -1)
		{
			if(!fired) //notice !  -> This says if NOT fired is true
			{
				fired = true; //Now it won't fire again

				//put your other if statement and your row code here
				if (Convert.ToInt32(view.dataView[view.Row]["QtyPer"]) > 1)
				{
					view.dataView[view.Row].BeginEdit();
					    view.dataView[view.Row]["QtyPer"]=1;
					view.dataView[view.Row].EndEdit();
				}
			}
		}
	}
}