Skip to main content
Answer

How can I programmatically fill an entity Attribute?

  • January 27, 2022
  • 5 replies
  • 356 views

darylbowman
Captain II
Forum|alt.badge.img+15

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

 

Best answer by rjean09

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

 

5 replies

Forum|alt.badge.img+7
  • Captain II
  • January 27, 2022

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


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • January 27, 2022

Yes, exactly


Forum|alt.badge.img+1
  • Semi-Pro III
  • Answer
  • January 27, 2022

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

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • January 28, 2022

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

 


Forum|alt.badge.img+1
  • Semi-Pro III
  • January 28, 2022

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