Skip to main content
Answer

Getting and setting UDF values in code

  • March 17, 2024
  • 3 replies
  • 233 views

Tony Lanzer
Pro III
Forum|alt.badge.img+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.

 

Best answer by andriikravetskyi35

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

3 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • March 18, 2024

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?


andriikravetskyi35
Jr Varsity I
Forum|alt.badge.img+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();


Tony Lanzer
Pro III
Forum|alt.badge.img+2
  • Author
  • Pro III
  • March 18, 2024

Thanks @andriikravetskyi35 !  That made it work.