Reputation: 11
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")]
Upvotes: 1
Views: 1151
Reputation: 669
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);
}
}
Upvotes: 1