Stumped on BPM Issue within Project Entry

Hey all, I have an issue within Project Entry I’m a bit stumped on. We have a BPM that fires when you go to create a new Variant, it is supposed to auto-update the Variance Reference ID (VarRefID) sequentially. If a project has no variant, it runs fine and adds the VarRefID as expected. If you add a 2nd, again this works fine. If you attempt to add an additional variant it attempts to overwrite the most recent VarRefID.


After adding new variant

This is ONLY occurring within our Live DB, I’m unable to re-produce the error within our TEST environment, (I will be restoring a newer backup of our Live DB to Test shortly, just waiting on access). I’ve checked the BPM in both the Live and Test environments, they are identical.

Here is the Pre-Processing:



Post-Processing:




Just to reiterate, the overwrite issue is only occurring within our Live DB not our Test DB. Any and all help would be greatly appreciated!

Welcome @Kcrounse !!

By any chance, did you upgrade recently?

Hey @jkane appreciate the welcome!

To my knowledge there has not been a recent update. To expand on that, I am actually new to this environment as of a week ago. So I’m actually still waiting on access to the Epicor App server to verify when the last update was.

When you pull that lastRefID in the foreach loop you’re not ensuring it’s actually the last one in any way. You’re banking on getting lucky that the last iteration of the foreach gets you the actual row you want.

You need some order by or something else to key off of.

The ordering of records could be different in different DBs. Especially when you start getting into Views vs Tables, stuff can get weird.

Tighten up the logic on that foreach loop and I think you’ll be good.

6 Likes

Hey Tom, thank you for the reply. I came up with the following:

string lastRefID = Db.PConVar
.Where(p => p.ProjectID == projectID)
.Select(p => p.VarRefID)
.OrderByDescending(p => p)
.FirstOrDefault();

if (!string.IsNullOrEmpty(lastRefID))
{
int refSeqNum;
if (int.TryParse(lastRefID.Replace(projectID, “”), out refSeqNum))
{
refSeqNum++;
InVarRefID = projectID + (refSeqNum < 10 ? “0” + refSeqNum : refSeqNum.ToString());
}
}
else
{
InVarRefID = projectID + “01”;
}

It’s working OK in our Test environment, just waiting to get the go-ahead to test in live. Let me know what you think.

1 Like

Hmm that may do the trick but I’m not 100% sure. Looks like that pconvar table doesn’t give you a whole lot to work with (I was thinking it would have something like a system generated line number but it doesn’t).

Instead of trying to identify the last “row/sequence” you might consider doing a count of pconvar rows where projectID = projectID, and then increment 1 to the count to get your next VarRefID…?

Use the sysRevID as the last.

2 Likes

It’s working in Live, and the powers at be are happy. I do have the following lined up that I may change to, based off your recommendation:

string lastRefID = Db.PConVar
.Where(p => p.ProjectID == projectID)
.Select(p => p.VarRefID)
.OrderByDescending(p => p)
.FirstOrDefault();

if (!string.IsNullOrEmpty(lastRefID))
{
int refSeqNum;
if (int.TryParse(lastRefID.Replace(projectID, “”), out refSeqNum))
{
refSeqNum++;
InVarRefID = projectID + (refSeqNum < 10 ? “0” + refSeqNum : refSeqNum.ToString());
}
}
else
{
int pconVarCount = Db.PConVar.Count(p => p.ProjectID == projectID);
InVarRefID = $“{projectID}{(pconVarCount + 1):D2}”;
}

Thank you for taking the time to assist with this!