Solved

How can I programmatically fill an entity Attribute?

  • 27 January 2022
  • 5 replies
  • 278 views

Badge +11

I am familiar with programmatically CRUDing records, but how can I use this functionality with Attributes?

 

CRCaseMaint caseGraph = PXGraph.CreateInstance<CRCaseMaint>();
CRCase newCase = caseGraph.Case.Insert(new CRCase());
caseGraph.Case.SetValueExt<CRCase.caseClassID>(newCase, caseClassID);
caseGraph.Case.SetValueExt<CRCase.customerID>(newCase, bAccount.BAccountID);
caseGraph.Case.SetValueExt<CRCase.subject>(newCase, subject);
newCase = caseGraph.Case.Update(newCase);
caseGraph.Actions.PressSave();

 

icon

Best answer by rjean09 28 January 2022, 00:07

View original

5 replies

Userlevel 7
Badge +5

Are you asking about getting/setting the value of an attribute associated with the Case record? 

Badge +11

Yes, exactly

Userlevel 3
Badge +1

Try something like this: 

// iterate attributes on case to set values

var answers = caseGraph.Answers.Select();

using (var ts = new PXTransactionScope())
{

foreach (CSAnswers att in answers)
{
if (att.AttributeID == "MYATTRIB")
{
att.Value = "My attribute value";
}
}

caseGraph.Answers.Cache.Update(answers);
caseGraph.Task.Cache.Update(caseGraph.Case);
caseGraph.Actions.PressSave();
ts.Complete();
}

 

Userlevel 7
Badge +17

Hi @Deetz  Below code might help you for your requirement.

 

   CRCaseMaint caseGraph = PXGraph.CreateInstance<CRCaseMaint>();
using (var ts = new PXTransactionScope())
{
CSAnswers objMyAttAns = caseGraph.Answers.Select().FirstTableItems.ToList().Where(x => x.AttributeID == "MYATTRIB" && x.RefNoteID == CaseRecordnoteID);

if (objMyAttAns != null)
{
objMyAttAns.Value = "My attribute value";
caseGraph.Answers.Cache.Update(objMyAttAns);
caseGraph.Actions.PressSave();
}
}

 

Userlevel 3
Badge +1

FYI, if you want to get the value of an attribute from a DAC field using PXSelector, take a look at this blog post: 

https://blog.zaletskyy.com/post/2020/08/17/post100

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