Skip to main content

I have added a new custom field that allows user to select an account. For that I have used existing Account attribute.

[Account(DisplayName = "Account", BqlField = typeof(INTranExt.usrAccount), Visibility = PXUIVisibility.Visible, Filterable = false, DescriptionField = typeof(Account.description), Required = false, AvoidControlAccounts = true)]
public virtual int? UsrAccount { get; set; }
public abstract class usrAccount : PX.Data.BQL.BqlInt.Field<usrAccount> { }

I have a field validating event on this field. When it returns an error is shows the AccountID instead of the AccountCD. How can is solve that. Can anyone please provide an insight here.

@tanuj81 share the code in the field validating event as well to review. 


protected void INTran_UsrAccount_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
{
// logic for calculation
if (!isAccountInAccountGroup)
{
e.Cancel = true;
throw new PXSetPropertyException(Messages.Test);
}
}

@Vinay Koppula But i don't think issue is here but you can have a look, Because the error is thrown perfectly as per the logic. I debugged the code and it is working fine. But in UI it shows AccountID in red text, not the AccountCD


@tanuj81  Issue is in the Field Verifying event code only, you are assuming it will automatically display AccountCD but the fact is we have to pass value to display in the field. 

 

Sample code that you put in the event code:

PX.Objects.GL.Account Act = PXSelect<PX.Objects.GL.Account, Where<PX.Objects.GL.Account.accountID,                 Equal<Required<PX.Objects.GL.Account.accountID>>>>.Select(Base, e.NewValue);

e.NewValue = Act?.AccountCD;
throw new PXSetPropertyException("Message.Test");

 


Another way to raise an exception and pass the AccountCD to display. 

cache.RaiseExceptionHandling<INTranExt.usrAccount >(e.Row, Act?.AccountCD, new PXSetPropertyException(errorMsg, PXErrorLevel.Error));

 


@tanuj81  Issue is in the Field Verifying event code only, you are assuming it will automatically display AccountCD but the fact is we have to pass value to display in the field. 

 

Sample code that you put in the event code:

PX.Objects.GL.Account Act = PXSelect<PX.Objects.GL.Account, Where<PX.Objects.GL.Account.accountID,                 Equal<Required<PX.Objects.GL.Account.accountID>>>>.Select(Base, e.NewValue);

e.NewValue = Act?.AccountCD;
throw new PXSetPropertyException("Message.Test");

 

Yes, I have reviewed in my case and it worked.

Thanks


@Vinay Koppula Thanks for such a detailed answer. 


@tanuj81 You are welcome! 

Thanks @sajids  for confirming.  


Reply