Setting UD Fields to a Variable

Sorry, was multi-tasking and didn’t read your post fully.

Add this to the top to be able to access the temp ds:

var tt = ds.ApInvHed.FirstOrDefault(r=>r.Updated());

Then you can set tt.Number03 = amtSum;

1 Like

Shouldn’t it officially be like below. Since it came from E9 it is a hybrid UD and lots of unofficial things work.

tt.SetUDField<decimal>("Number03", amtSum);
2 Likes

That’s a way, sure.
I’ve literally never used that syntax, though, soooo… :woman_shrugging:t2:

Skin your cat however you want! :scream_cat:

1 Like

Ok haha, I was looking at the first bit of code you sent and was like “oh, I’m in way over my head”. This looks much more familiar, but unfortunately, it’s still saying that APInvHedRow doesn’t contain a definition for “Number03”.

This freed me from the syntax error, but I got one of those wonky error messages when I tried to test it (that usually comes from something wrong with my foreach loop). Gonna run some null tests on it to see if that’s what is causing the issue.

I had something in post processing ChangeRefPONum already that had come thru the ABL conversions from 9 that I slammed your code into and added a piece I use to sum previous quantities, but has sql do the work.

This runs, but I don’t have Number03
image

/* sum amount */

foreach (var tt in ds.APInvHed)
{
    
    using (System.Transactions.TransactionScope txScope = IceDataContext.CreateDefaultTransactionScope())//start the transaction
    {
        double amtSum = Db.APInvHed.Where(i=> i.Company == CompanyID && tt.REFPONum == i.REFPONum).Sum(x=> (double?) x.DocInvoiceVendorAmt) ?? 0; //has to be double because sql returns that if null
           
          Ice.Diagnostics.Log.WriteEntry($" amtSum is {amtSum} ");

        //tt.SetUDField<decimal>("Number03", (decimal)amtSum);
       
              
        txScope.Complete();//commit the transaction
    }
}

So I ran a bunch of null tests and found that the foreach was good. It was when I took out the statement assigning amtSum to Number03 that the error went away so it seems like I still need to fix that part. Not sure how it compiled if it was just going to throw an error when the method gets called…

Will have to dig into that part more, but I appreciate all of the help so far!

Maybe Number03 is somehow missing. Can you see it in Extended UD table maintenance and in the dbo.APInvHed view in SSMS?

I assigned the sum in my routine to rounding and it shows in the data.
image

1 Like

That’s a good point actually.

Did you ever have data in that field in E9? If not, the upgrade won’t bring that field over and it won’t exist.

2 Likes

It does exist:

image

Going to try some other ways to call that table since there’s a “_UD” at the end of it.

The database context will include the _UD table in the ds.APInvHed object. Have you run a debugger on the code to see what the ds.APInvHed object looks like?

I’m sure there’s a better way to debug, but I set
callContextBpmData.Character05 = ds.APInvHed.ToString();
and threw it on a show message widget and got this:

image

What exactly did these messages say?

image

Have determined that this usually stems from something wrong with my BPM.

Check the event viewer on the server for the specific message. Should help you narrow it down more.

I think it’s tt.SetUDField<decimal>("Number03", amtSum); that is causing it because when I comment that out, it runs fine. It just seems like every time I try and fill that UD field, things go wrong.

Although, I am curious about this event viewer you speak of. Where would I find that? (I apologize for my inexperience)

It would be on the server (here’s to hoping you’re not a SaaS customer!).

Unfortunately, we are on the cloud…

Shoutout to @klincecum for this: Server Event Log Dashboard - Code Review / Sharing - Epicor User Help Forum (epiusers.help)

1 Like

I would ask the SaaS team to regenerate the data model to see it that would fix is since you can’t see the dbo view.

1 Like

So, one of my coworkers was able to figure this out. The
var tt = ds.APInvHed.FirstOrDefault(); line helps, I just had to remove the r=>r.Updated() part from the FirstOrDefault() method. I think that was causing it to return 0. To set the UD field, @gpayne’s tt.SetUDField("Number03", amtSum); worked perfectly!

Thank you @hmwillett, @gpayne, @Doug.C for all of the help!