Skip to main content
Solved

Getting and setting UDF values in code


Tony Lanzer
Semi-Pro I
Forum|alt.badge.img+1

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

View original
Did this topic help you find an answer to your question?

3 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3404 replies
  • 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
Semi-Pro I
Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • 75 replies
  • March 18, 2024

Thanks @andriikravetskyi35 !  That made it work.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings