Skip to main content
Solved

Need help with Creating Custom "Related" field


Eg: I am trying to create a “Customer” related field in “Invoices” screen.

 

Dear Friends,

I am trying to create a custom “Related” field and it doesn’t work for some reason, so need your input.

 

I created a new Customization Project, and in the Data Access section for Invoice, I created a new field:

 

Lets say the Field name is “Shipping Customer”. I added the following as part of field attributes:

[CustomerActive(Visibility = PXUIVisibility.SelectorVisible, DescriptionField = typeof(Customer.acctName),Filterable=true, TabOrder=2)]
[PXUIField(DisplayName="ShippingCustomer")]

Once the field is created, I added it to the Invoice Screen, and it appears fine (woohoo!).

 

 

But when I save the Invoice, the field value is not getting saved into the DB. Any clues why? 

Thanks for your help!

Best answer by ray20

Can I take a whole look at your DAC? And your screen field.
You have to make the type match.
Like, Customer is stored in DB in Int, so the selector should use BAccountID in the typeof 

Below is an example of add a “warehouse” field on user.

[PXDBInt]
[PXUIField(DisplayName="Default Warehouse")]
[PXSelector(typeof(INSite.siteID),SubstituteKey = typeof(INSite.siteCD),DescriptionField = typeof(INSite.descr))]

 

View original
Did this topic help you find an answer to your question?

6 replies

Forum|alt.badge.img+5
  • Captain II
  • 398 replies
  • Answer
  • May 20, 2021

Can I take a whole look at your DAC? And your screen field.
You have to make the type match.
Like, Customer is stored in DB in Int, so the selector should use BAccountID in the typeof 

Below is an example of add a “warehouse” field on user.

[PXDBInt]
[PXUIField(DisplayName="Default Warehouse")]
[PXSelector(typeof(INSite.siteID),SubstituteKey = typeof(INSite.siteCD),DescriptionField = typeof(INSite.descr))]

 


  • Author
  • Freshman I
  • 10 replies
  • May 20, 2021

Thank you, Ray.

I am new to Acumatica, so here are the steps that I did:

  1. Create the new field like this:
  1. Added the Customer line (copied from Customer ID field) and published it once.

[PXDBInt]
[PXUIField(DisplayName="Test Customer")]
[CustomerActive(Visibility = PXUIVisibility.SelectorVisible, DescriptionField = typeof(Customer.acctName),Filterable=true, TabOrder=2)]

  1. Added it to the UI screen:
  1. Added the Field and published again:
  1. After publishing, it doesn’t allow me to view the record, and says “Invalid Cast”.
  1. And the UI label always defaults to “Customer” as well, in the form layout.

By DAC, do you mean the source code?

 

Thanks again for your help!

 


  • Author
  • Freshman I
  • 10 replies
  • May 20, 2021

Hi @ray20, Your idea gave me some inspiration to try out the PXSelector, but when I use it, I always get this error: Specified cast is not valid:

I converted yours into a Customer reference, something like:

[PXDBInt]
[PXUIField(DisplayName="Test Customer")]
[PXSelector(typeof(Customer.bAccountID),SubstituteKey = typeof(Customer.acctCD),DescriptionField = typeof(Customer.acctName))]

 

 


Forum|alt.badge.img+5
  • Captain II
  • 398 replies
  • May 20, 2021

Hello,

    I guess the problem happens at the add a control step.
Can you try the control type as “selector”?

  I did not use “segmentmask” type before, so I am not sure. I previously use “selector” type and it is OK.

 

       Note: when you select the “Selector” as the control step, it looks like it would change automatically to “textedit”.  please ignore it.

          Just make sure you have the right codes in DAC, and then publish.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3406 replies
  • May 20, 2021

@paramesh 

Below the DAC and .aspx page fields to add the Customer ID field.

DAC

#region USRKCustomerID
public abstract class uSRCustomerID : PX.Data.BQL.BqlInt.Field<uSRCustomerID> { }
[PXDefault]
[CustomerActive(DisplayName = "Customer ID", Visibility = PXUIVisibility.SelectorVisible, Required = false, DescriptionField = typeof(Customer.acctName), Filterable = true)]
public virtual Int32? USRCustomerID { get; set; }
#endregion

 

.aspx Page:

<px:PXSegmentMask CommitChanges="True" ID="USRCustomerID" runat="server" DataField="USRCustomerID" ></px:PXSegmentMask>


  • Author
  • Freshman I
  • 10 replies
  • May 24, 2021

Hi @ray20 , @Naveen B ,

 

Thanks for your input. Both of your options worked for me.

The problem was with our existing field - maybe the DB column was incorrect when I created first time, and even when I deleted and recreated, it was still not working. 


I just created new fields and they're working fine now.

Thanks and have a nice day!
Paramesh


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings