Solved

Getting and setting UDF values in code

  • 17 March 2024
  • 3 replies
  • 49 views

Userlevel 4
Badge +2

I’m trying to copy UDF values from a Project Quote to a Project when the quote gets converted to a new project.  In my Project Quote graph extension, I have the following code...
 

PMQuote quote = Base.Quote.Current;
PXCache baseCache = Base.Quote.Cache;

var udfONSITECUST = (PXStringState)baseCache.GetValueExt(quote,
"AttributeONSITECUST");
var udfDESIGNENGR = (PXStringState)baseCache.GetValueExt(quote,
"AttributeDESIGNENGR");
var udfSALESREPRE = (PXStringState)baseCache.GetValueExt(quote,
"AttributeSALESREPRE");

using (PXTransactionScope ts = new PXTransactionScope())
{
ProjectEntry projectEntry = PXGraph.CreateInstance<ProjectEntry>();
PMProject project = projectEntry.Project.Current =
PMProject.PK.Find(projectEntry, quote.QuoteProjectID);
PXCache cache = projectEntry.Project.Cache;

projectEntry.Project.Cache.SetValueExt(project, "AttributeONSITECUST",
udfONSITECUST?.Value);
projectEntry.Project.Cache.SetValueExt(project, "AttributeDESIGNENGR",
udfDESIGNENGR?.Value);
projectEntry.Project.Cache.SetValueExt(project, "AttributeSALESREPRE",
udfSALESREPRE?.Value);

projectEntry.Actions.PressSave();

ts.Complete();
}

When the new project is opened, the UDF fields have no value.  If I step through it, I see the values get and set, so the save to database for the UDFs doesn’t seem to be working.  Any suggestions to resolve or to accomplish this differently? I could update the UDF table explicitly, but yuck.

 

icon

Best answer by andriikravetskyi35 18 March 2024, 08:08

View original

3 replies

Userlevel 7
Badge +17

Hi @Tony Lanzer  I don’t see any issues with the code. Can you please let me know at which place you have written this code or share the code file here?

Userlevel 5
Badge +1

Hi Community,

SetValueExt() method is mostly developed for using in FieldUpdating, FieldUpdated, RowUpdated events, as we can not raise method Cache.Update(), because it will create infinitive foreach loop. 

Maybe try invoke this method, before saving:

projectEntry.Project.UpdateCurrent();

Userlevel 4
Badge +2

Thanks @andriikravetskyi35 !  That made it work.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved