Data persisting in a users session

This is a weird one and I’m completely lost on what it could be.
I have a customization I wrote on Mass Print AR Invoices that simply cycles through a list of invoices that the user enters and prints them to PDF. When the user enters an invoice number in the blank field next to the add button and clicks “add”, it adds a row to an empty data table that is created when the form is initialized.
If the customization is called from a invoice key field like in the AR invoice tracker, it will bring in the invoice number from the EpiDataView. It’s nothing earth shattering, but it might be helpful.
Below is my code for this customization:

// **************************************************
// Custom code for ARInvForm
// Created: 5/20/2016 3:08:40 PM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.UI;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using System.Text.RegularExpressions;

public class Script
{
// ** Wizard Insert Location - Do Not Remove ‘Begin/End Wizard Added Module Level Variables’ Comments! **
// Begin Wizard Added Module Level Variables **

private EpiDataView edvReportParam;
// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **
DataTable dtInput = new DataTable();
string Invoice;
bool printed = false;
public void InitializeCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
	// Begin Wizard Added Variable Initialization

	this.edvReportParam = ((EpiDataView)(this.oTrans.EpiDataViews["ReportParam"]));
	this.edvReportParam.EpiViewNotification += new EpiViewNotification(this.edvReportParam_EpiViewNotification);
	// End Wizard Added Variable Initialization

	// Begin Wizard Added Custom Method Calls

	this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
	this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
	this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
	this.txtAddInvoice.Validated += new System.EventHandler(this.txtAddInvoice_Validated);
	this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
	// End Wizard Added Custom Method Calls
	dtInput.Columns.Add("Invoice",typeof(int));
	dtInput.Columns.Add("Printed", typeof(bool));
}

public void DestroyCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
	// Begin Wizard Added Object Disposal

	this.edvReportParam.EpiViewNotification -= new EpiViewNotification(this.edvReportParam_EpiViewNotification);
	this.edvReportParam = null;
	this.btnAdd.Click -= new System.EventHandler(this.btnAdd_Click);
	this.btnRemove.Click -= new System.EventHandler(this.btnRemove_Click);
	this.btnPrint.Click -= new System.EventHandler(this.btnPrint_Click);
	this.txtAddInvoice.Validated -= new System.EventHandler(this.txtAddInvoice_Validated);
	this.btnClear.Click -= new System.EventHandler(this.btnClear_Click);
	// End Wizard Added Object Disposal

	// Begin Custom Code Disposal

	// End Custom Code Disposal
}

private void edvReportParam_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.Initialize))
	{
		if ((args.Row > -1))
		{
		//MessageBox.Show(edvReportParam.dataView[edvReportParam.Row]["InvoiceNum"].ToString());
		}
	}
}


private void ARInvForm_Load(object sender, EventArgs args)
{
	// Add Event Handler Code
	dtInput.Clear();
	grdInput.DataSource = dtInput;
	EpiDataView dvRP = (EpiDataView)oTrans.EpiDataViews["ReportParam"];
	Invoice = dvRP.dataView[dvRP.Row]["InvoiceNum"].ToString();	
	if (Invoice != "0")
	{
		dtInput.Rows.Add(Invoice, printed);
	}
}

private void ReadOnlyDT()
{
foreach (DataColumn dc in dtInput.Columns)
	{
	//dc.ReadOnly = true;
	}
}

private void btnAdd_Click(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **
	//Invoice = txtAddInvoice.Value.ToString();
	if (String.IsNullOrEmpty(txtAddInvoice.Text)) return;
	Invoice = txtAddInvoice.Value.ToString();
	//regex
	Regex regex = new Regex(@"^[0-9]{6}$");
	Match match = regex.Match(Invoice);
	if (match.Success)	
	{
		dtInput.Rows.Add(Invoice, printed);
	}
	else
	{
		MessageBox.Show("Enter a 6 digit invoice number");
	}
	txtAddInvoice.Clear();
	txtAddInvoice.Focus();
}

private void btnRemove_Click(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **	
	
	if (String.IsNullOrEmpty(txtAddInvoice.Text)) return;
	Invoice = txtAddInvoice.Value.ToString();					
	for(int i = dtInput.Rows.Count-1;i>=0;i--)//backwards loop 
	{
		DataRow dr = dtInput.Rows[i];
			if (dr["Invoice"].ToString() == Invoice)
			{
				dr.Delete();//will remove any duplicate entries, so be careful
			} 
	}	
	grdInput.Refresh();
	txtAddInvoice.Clear();
}

private void btnPrint_Click(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **
	txtNumberInvoicesSent.Value = 0;
	if (dtInput.Rows.Count<1){ MessageBox.Show("No Invoices Selected for Print"); 
	return;}
	EpiDataView dvRP = (EpiDataView)oTrans.EpiDataViews["ReportParam"];
	string workID = oTrans.WorkStationID.ToString();
	try {
		foreach (DataRow dr in dtInput.Rows)
		{
			dvRP.dataView[dvRP.Row]["InvoiceNum"] = dr["Invoice"];
			dvRP.dataView[dvRP.Row]["AutoAction"] = "SSRSPREVIEW";
			dvRP.dataView[dvRP.Row]["WorkstationID"] = workID;
			dr["Printed"] = true;
			oTrans.Update();					
			oTrans.SubmitToAgent("SystemTaskAgent", 0, 0);
		}
		
		txtNumberInvoicesSent.Value = dtInput.Rows.Count;
		oTrans.PushDisposableStatusText("Reports Submitted for Preview...", true);
	}
	catch (Exception ex)
	{
	MessageBox.Show(ex.Message);
	}
}

private void txtAddInvoice_Validated(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **		
}

private void btnClear_Click(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **
	dtInput.Clear();
	txtNumberInvoicesSent.Clear();
}

}

I have one user who always has a persistent record in the list of “to be printed” invoices. Interestingly, it is always the same invoice record that persists. There is nothing unique about this invoice, from what I can tell.

When I have any other user pull up this customization, it does not have this invoice record selected.
I have tried clearing the users cache, clearing the users personification, but nothing is working. Any tips are appreciated, thank you

1 Like

Maybe they have that record set to Auto Load on that screen. I forgot how you check / do this…

Let me check, thank you for the idea

Yeah if you click Save Defaults It’ll do that. Just tested it (Actions -> Save Default)
Action -> Remove Defaults should fix it… (if that’s the issue)

I looked at Tools: options; the user didn’t have anything selected for the the “As the Form Opens” options.
I also did what you suggested with the Actions–>Remove defaults, but it appeared to do nothing.

Hmmmmmmmmmmmmmm… Not saying I don’t believe you Aaron… but…
image

LoL, hmm put a messagebox on your Load_Form in your if statement, to see if its finding the InvoiceNum in the ReportParam dataview.

2 Likes

Haha trust me, I hope this is my fault! I don’t like problems that don’t have an answer.
Let me add that debugging code, hold on

It shows 0 for me, and now my user says it shows 0 for her as well as cleared out the random invoice.

Makes about zero sense to me how that would fix it, but I’ll take it :slight_smile:
Not sure which answer should be marked as solved haha

1 Like

I’m assuming you cleared her Epicor Cache before? If not … then that’s the answer. When you update the customization you force the cache to refresh

2 Likes

I did clear the cache, but maybe it didn’t actually clear until the code was different. Either way, I really appreciate the help. This user has been asking about this issue for about a year :slight_smile: and I finally found time to work on it

Does anyone know where in the DB the Report Defaults are saved? Thanks,

Just found it in ICE.RptDefault

Ran into this one again. The fix was to delete the users settings from the RptDefault table. Does anyone know how those get populated and why it seems to be the only way to clear them out?

@Aaron_Moreng I believe that information is saved when a user selects Actions->Save Defaults from a print report dialog. Selecting Actions->Remove Defaults should get rid of it but maybe I’m over simplifying it.

What’s weird is that I tried that and it wouldn’t release. Oh well, good to know the “correct” way to do it :slight_smile:

I’m not sure there is a correct way to do anything with this software :rofl:

2 Likes

Any ideas how to add a custom parameter here to save with Save Defaults.

Hi! Many apologies for reviving this long-dormant thread, but I’m a newb and am experiencing a similar issue for one user.

To clarify, would you use SQL to delete the user settings from the ICE.RptDefault table, or would you do this from within Epicor somehow? Do you only remove the user settings for the affected form?

The specific error my user is getting when trying to print Remittance Advice is “Print Order must be specified”, but there is nowhere to specify Print Order for our Manual Check payment method. When I look in Rpt.Default, I don’t see a ParamName specifically for Print Order.

Any additional info you can provide would be greatly appreciated. Thank you in advance!