Solved

Need help with Creating Custom "Related" field

  • 20 May 2021
  • 6 replies
  • 285 views

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!

icon

Best answer by ray20 20 May 2021, 10:11

View original

6 replies

Userlevel 6
Badge +5

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))]

 

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!

 

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))]

 

 

Userlevel 6
Badge +5

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.

Userlevel 7
Badge +17

@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>

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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved