Skip to main content
Answer

How to update user defined fields

  • December 12, 2024
  • 7 replies
  • 192 views

How would I go about updating user defined fields programmatically?

I can’t find any examples or any documentation on how to do this. 

Found a post showing the below, but I need to update UDF fields on IN Issue, IN transfer and IN Receipts, and none of  them has Answers view. 

 

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

 

Best answer by DipakNilkanth

Hi ​@mauritzv,

User Defined fields are based on attributes and stored in a sibling table. For example for INTran you have the table INTranKvExt.

You can create a DAC for that table and query it. Fields have a prefix ‘Attribute’ tied and it is link to the parent entity by NoteID - RecordID. Also you can see the definition in the table CSScreenAttribute.

To access the value from the graph you can try using cache.GetValueExt.

This post helps you to achieve the same.

 

7 replies

Forum|alt.badge.img+1
  • Jr Varsity III
  • December 12, 2024

Hi ​@mauritzv ,
You need to use INTranKvExt table. Please go through below post.
 

Hope it will work.


DipakNilkanth
Pro III
Forum|alt.badge.img+13
  • Pro III
  • Answer
  • December 12, 2024

Hi ​@mauritzv,

User Defined fields are based on attributes and stored in a sibling table. For example for INTran you have the table INTranKvExt.

You can create a DAC for that table and query it. Fields have a prefix ‘Attribute’ tied and it is link to the parent entity by NoteID - RecordID. Also you can see the definition in the table CSScreenAttribute.

To access the value from the graph you can try using cache.GetValueExt.

This post helps you to achieve the same.

 


  • Author
  • Freshman I
  • December 12, 2024

Hi

 

I want to update them. I can read the values by using this example:

PXGraph tmpGraph = new PXGraph();
PMProject tmpProject = tmpGraph.Select<PMProject>().FirstOrDefault(x => x.ContractID == project.ContractID);
PXFieldState trfJOBAttribute = (PXFieldState)tmpGraph.Caches[typeof(PMProject)].GetValueExt(tmpProject, "TFRJOB_Attributes");

 

I am now attempting @noorula77 suggestion by creating a DAC. 

However I believe it should be INRegisterKvExt and not INTranKvExt 

   public class INIssueEntryExtension : PXGraphExtension<INIssueEntry>
{
public static bool IsActive() => true;
SelectFrom<INRegisterKvExt>.Where<INRegisterKvExt.recordID.IsEqual<INRegister.noteID.FromCurrent>>.View UsrDefinedFieldsView;
}


[Serializable]
[PXCacheName("INRegisterKvExt")]
public class INRegisterKvExt : IBqlTable
{
#region RecordID
[PXDBGuid(IsKey = true)]
[PXUIField(DisplayName = "Record ID")]
public virtual Guid? RecordID { get; set; }
public abstract class recordID : PX.Data.BQL.BqlGuid.Field<recordID> { }
#endregion

#region FieldName
[PXDBString(50, IsKey = true, InputMask = "")]
[PXUIField(DisplayName = "Field Name")]
public virtual string FieldName { get; set; }
public abstract class fieldName : PX.Data.BQL.BqlString.Field<fieldName> { }
#endregion

#region ValueNumeric
[PXDBDecimal()]
[PXUIField(DisplayName = "Value Numeric")]
public virtual Decimal? ValueNumeric { get; set; }
public abstract class valueNumeric : PX.Data.BQL.BqlDecimal.Field<valueNumeric> { }
#endregion

#region ValueDate
[PXDBDate()]
[PXUIField(DisplayName = "Value Date")]
public virtual DateTime? ValueDate { get; set; }
public abstract class valueDate : PX.Data.BQL.BqlDateTime.Field<valueDate> { }
#endregion

#region ValueString
[PXDBString(256, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Value String")]
public virtual string ValueString { get; set; }
public abstract class valueString : PX.Data.BQL.BqlString.Field<valueString> { }
#endregion

#region ValueText
[PXDBString(IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Value Text")]
public virtual string ValueText { get; set; }
public abstract class valueText : PX.Data.BQL.BqlString.Field<valueText> { }
#endregion
}

But now just not sure how to use this. Trying now and will do an update. 


DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi ​@mauritzv,

If you are able to read the values using GetValueExt, Try to update using SetValueExt as described in the post I have shared in previous comment.


  • Author
  • Freshman I
  • December 12, 2024

Thanks, the DAC approach did the trick. For reference here is my code that sets the UDF using the DAC from my previous post. 

 

 

    graphINIssueEntry = PXGraph.CreateInstance<INIssueEntry>();
INIssueEntryExtension issueEntryExt = graphINIssueEntry.GetExtension<INIssueEntryExtension>();
inIssueRegister = new INRegister();
inIssueRegister.DocType = INDocType.Issue;
inIssueRegister.TranDate = dateTimeStart.Date;
inIssueRegister.FinPeriodID = finPeriod.FinPeriodID;
inIssueRegister.TranDesc = project.Description;
inIssueRegister.Hold = false;
inIssueRegister.BranchID = branchA.BranchID;

inIssueRegister = graphINIssueEntry.issue.Current = graphINIssueEntry.issue.Insert(inIssueRegister);
INRegisterKvExt regKvExt = issueEntryExt.UsrDefinedFieldsView.Insert();
issueEntryExt.UsrDefinedFieldsView.SetValueExt<INRegisterKvExt.fieldName>(regKvExt, "AttributeDRIVER");
issueEntryExt.UsrDefinedFieldsView.SetValueExt<INRegisterKvExt.valueString>(regKvExt, "testing");
issueEntryExt.UsrDefinedFieldsView.SetValueExt<INRegisterKvExt.recordID>(regKvExt, inIssueRegister.NoteID);


inIssueRegister = graphINIssueEntry.issue.Update(inIssueRegister);

 


  • Author
  • Freshman I
  • December 12, 2024

@Dipak Nilkanth I have tried that without any luck, maybe I was doing it wrong?

I tried it like this:

 

 graphINIssueEntry.issue.Cache.SetValueExt(inIssueRegister, "AttributeDRIVER", "testing");

Would be nice if a simpler solution works, instead of creating a DAC. 


darylbowman
Captain II
Forum|alt.badge.img+15
  • December 12, 2024
 graphINIssueEntry.issue.Cache.SetValueExt(inIssueRegister, "AttributeDRIVER", "testing");

This looks correct if inIssueRegister is a row in the issue cache