1

I'm trying to auto-populate a field based on another field. I have a selector field for Contracts and I created a Manager 1 field for the primary manager which is captured in the Contracts screen.

I am able to get the correct results when opening the selector field for Manager 1. It populates the contract code and the manager associated with it; however, I want it to fill in the field automatically once I select a contract. I've tried using PXDefault, but didn't have any luck. The code below is what I have working so far:

[PXInt] 
[PXUIField(DisplayName="Manager 1")] 
[PXSelector(typeof(Search2<PX.Objects.CR.BAccount.bAccountID, 
  InnerJoin<JPMContract, 
  On<JPMContract.contractMgrBAccountID, 
  Equal<PX.Objects.CR.BAccount.bAccountID>>>>), 
  typeof(JPMContract.contractCode), 
  typeof(PX.Objects.CR.BAccount.acctCD), 
  typeof(PX.Objects.CR.BAccount.acctName), 
  SubstituteKey = typeof(PX.Objects.CR.BAccount.acctCD), 
  DescriptionField = typeof(PX.Objects.CR.BAccount.acctName))]

Again, when I open the selector field and select the corresponding result, I get the results I want, but I want it to do this for me once a contract is selected. Any advice?

UPDATE: I got it to only return the one result I need in the selector but it still doesn't populate with that one result in the field.

[PXInt]
[PXSelector(typeof(Search2<PX.Objects.CR.BAccount.bAccountID,
   InnerJoin<JPMContract,
   On<JPMContract.contractMgrBAccountID,
   Equal<PX.Objects.CR.BAccount.bAccountID>>>,
   Where<JPMContract.jPMContractID, Equal<Current<JPMSubContract.jPMContractID>>>>),
   typeof(JPMContract.contractCode),
   typeof(PX.Objects.CR.BAccount.acctCD),
   typeof(PX.Objects.CR.BAccount.acctName),
   SubstituteKey = typeof(PX.Objects.CR.BAccount.acctCD),
   DescriptionField = typeof(PX.Objects.CR.BAccount.acctName))]
[PXDefault(typeof(Search2<PX.Objects.CR.BAccount.bAccountID,
   InnerJoin<JPMContract,
   On<JPMContract.contractMgrBAccountID,
   Equal<PX.Objects.CR.BAccount.bAccountID>>>,
   Where<JPMContract.jPMContractID, Equal<Current<JPMSubContract.jPMContractID>>>>))]
[PXUIField(DisplayName="Manager 1")]
  • You should use `PXFormulaAttribute` or write the `FieldSelecting` event for this field which will get the corresponding value and set to `e.NewValue`. – Samvel Petrosov Jun 18 '19 at 18:15

1 Answers1

1
public sealed class DACExt : PXCacheExtension<PrimaryDAC>
{
    // For this field in aspx file set CommitChanges=true
    [PXDBInt]
    [PXSelector(typeof(Search<Table.field0>))]
    [PXUIField(DisplayName = "Field 1")]
    public int? Field1 { get; set; }
    public abstract class field1 : IBqlField { }

    [PXInt]
    //This line auto-populate a field based on Field1 field
    [PXDefault(typeof(Search<Table1.field2, Where<Table1.field0, Equal<Current<Table.field0>>>>), PersistingCheck = PXPersistingCheck.Nothing)]
    [PXUIField(DisplayName = "Field 2", Enabled = false)]
    public int? Field2 { get; set; }
    public abstract class field2 : IBqlField { }
}


public virtual void PrimaryDAC_Field1_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
    if (e.Row is PrimaryDAC row)
    {
        sender.SetDefaultExt<DACExt.field2>(e.Row);
    }
}  
Samvel Petrosov
  • 7,580
  • 2
  • 22
  • 46
Vardan Vardanyan
  • 649
  • 5
  • 12
  • This code won't work for him, he has unbound field and already created record. PXDefault is working only during inserting of the record. Also, it is mentioned in the question that PXDefault didn't work for this case. – Samvel Petrosov Jun 18 '19 at 18:13
  • Yeah this didn't work for me. I understand the concept, but it's not working on insertion of the record either. Nothing populates. – meaginmarie Jun 18 '19 at 18:41
  • @meaginmarie do you want to store that value in the database or just to show it? – Samvel Petrosov Jun 18 '19 at 18:52
  • I don't necessarily need to save it if that's the only way it'll work since it's already stored somewhere else. But I will take either way at this point honestly. – meaginmarie Jun 18 '19 at 19:02
  • so i got it to where it'll just return the one result i'm looking for in the selector but it doesn't populate it. – meaginmarie Jun 18 '19 at 21:00