Setting UD Fields to a Variable

Hello! In the process of transitioning to Kinetic from E9. In AP Invoice Entry, we have a few UD fields that get updated on either the ChangeRefPONum or PreUpdate methods. Have some code that sums up the amount of money invoiced to date for a specific PO, but when I try and assign it to the respective UD field, I get this error:
“The left-hand side of an assignment must be a variable, property, or indexer”

ds.APInvHed[0].UDField<System.Decimal>("Number03") = amtSum;

where amtSum is the iterated variable. If I switch the two values, the code compiles, so I didn’t think it would be a syntax issue, but maybe it is??? Have been able to perform calculations in other methods with the UD Field in that form, but have yet to set a variable to one.

If anyone has any advice on this issue, I would greatly appreciate it!

:scream: :grimacing:

Try this:

ds.APInvHed[0].Number03 = amtSum;

If I recall, E9 had Number03 as a stock field, so you should be able to reference as such.
If it can’t find it, do:

ds.APInvHed[0]("Number03") = amtSum;

Thank you for the quick reply!

Unfortunately, I tried the first option and it couldn’t find the variable. The 2nd option threw an error saying “Method name expected”. I added in a “.” after ds.APInvHed[0] to see if that would help (really just a shot in the dark) and got an error saying “Identifier expected”. Is there a method that calls on UD fields?

If there is, I’ve never used it. ¯\_(ツ)_/¯

May I see the rest of your code?

This is all there is to it:

decimal amtSum = 0.0m;

int origPONum = ds.APInvHed[0].REFPONum;

var matchingRows = (from row in Db.APInvHed where row.REFPONum == origPONum select row);

foreach(var invHedRow in matchingRows)
  amtSum += invHedRow.DocInvoiceVendorAmt;

ds.APInvHed.("Number03") = amtSum;

EDIT: there is a [0] after d.APInvHed., I just forgot to add it back oops

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);

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

/* 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.

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.


It does exist:


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:


What exactly did these messages say?


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)