Question

Trying to create a custom Field that defaults from another custom field


Userlevel 3
Badge

I am working in the Customization Project Editor.  I went in and added on the Customer Screen a new custom field usrDate_Of_Loss.  I think its BAccountExt.usr_Date_Of_Loss.  I added it to the customer. 

I also added a usrDateOfLoss to the invoice 

ARRegisterExt.usrDateOfLoss I believe is what it is called. 

I also added the Default code and the Formula attributes where the custom field is declared in the Customization Project Editor.  I am  adding it to the Attributes section,  I put in bold below: 

 

[PXDBDate]
[PXUIField(DisplayName="Date Of Loss")]

[PXDefault(typeof(Search<BAccountExt.usrDate_Of_Loss , 
            Where<Customer.CustomerID, Equal<Current<ARInvoice.CustomerID>>>>), 
            PersistingCheck = PXPersistingCheck.Nothing)]
[PXFormula(typeof(Default<ARInvoice.CustomerID>))]

 

It is looking up I hope that custom field from Customer to put in the Invoice DateofLoss Field. 

The error on validation is: 

\App_RuntimeCode\PX_Objects_AR_ARRegister_extensions.cs(36): error CS0426: The type name 'CustomerID' does not exist in the type 'Customer'
\App_RuntimeCode\PX_Objects_AR_ARRegister_extensions.cs(36): error CS0426: The type name 'CustomerID' does not exist in the type 'ARInvoice'
\App_RuntimeCode\PX_Objects_AR_ARRegister_extensions.cs(38): error CS0426: The type name 'CustomerID' does not exist in the type 'ARInvoice'
\App_RuntimeCode\PX_Objects_AR_ARRegister_extensions.cs(36): error CS0426: The type name 'CustomerID' does not exist in the type 'Customer'

 

Do I need to add declarations to the Attributes section in Customization Project Editor, that doesn’t seem to make sense. Any help would be appreciated.

Image below

 


20 replies

Userlevel 5
Badge +1

your issue is Casing. Types in this area are camel case with the first letter being lower case.

So it should be ARInvoice.customerID

The field names after the dot should be lowercase.this would be everywhere in those attributes. Your custom field is good but the rest need adjusted.

Userlevel 3
Badge

Thats fantastically simple to fix. Thank you!

Userlevel 3
Badge

And to close the loop, Customer.CustomerID had to be Customer.acctCD.  So changing case and the wrong field made it work.  Thanks

Userlevel 3
Badge

But the default is not working of course...

Userlevel 7
Badge +5

Something else to watch for is that you should avoid using the underscore character in your DAC field names.

Userlevel 5
Badge +1

@ddunn thanks for pointing that out. I had meant to mention it. In Acumatica Business Logic the underscores drive some of the functionality and if you have underscores in your field names it can make other customization harder. I won’t necessarily break anything but will make it harder to customize business logic related to those fields later.

Badge +12

@edwardmcgovern97  Try this Default Attribute: 

[PXDefault(typeof(SearchFor<BAccountExt.usrDate_Of_Loss>.
In<SelectFrom<BAccount>.
Where<BAccount.bAccountID.IsEqual<ARInvoice.customerID>>>))]

You’ll need to have the using:

using PX.Data.BQL.Fluent;

 

Userlevel 3
Badge

Are we saying that the default is not happening because of the underscores? 

 

Badge +12

@edwardmcgovern97 - No, it’s just not a best practice.

Badge +12

If I’m right, the default is not happening because you’re searching for the value of a DAC extension of BAccount, but your Where is pulling from Customer (a completely different table). You could also change your statement to:

[PXDefault(typeof(Search<BAccountExt.usrDate_Of_Loss, 
Where<BAccount.baccountID, Equal<Current<ARInvoice.customerID>>>>),
PersistingCheck = PXPersistingCheck.Nothing)]

I don’t like the old BQL so I used F-BQL

Userlevel 3
Badge

Ok I am trying the code you suggested and it does not seem to fire. I get no default

 

Badge +12

Apologies, I didn’t see you were using the visual editor. I don’t believe you can use ‘using’ there. F-BQL may work there without that, or if not, use my BQL version.

Userlevel 3
Badge

I get no prompt for anything missing when I compile without the using and deploy and still get no default using yours or my code

Badge +12

I may have been wrong about the tables. I actually think that since they restructured the BAccount and Customer relation, you may have been right. However, in your original attribute, you used Customer.customerID, which is not a valid field, as you saw, but Customer.acctCD is also not going to match.

Try this: 

[PXDefault(typeof(Search<BAccountExt.usrDate_Of_Loss , 
Where<Customer.baccountID, Equal<Current<ARInvoice.customerID>>>>),
PersistingCheck = PXPersistingCheck.Nothing)]

 

I’m not sure if you need the Current<> or not. I’d try it both ways.

Don’t think I can help you more than that.

Userlevel 3
Badge

Got it.  Customerid is an integer.  Acctcd is the string holding the account 

But I tried yours and 

\App_RuntimeCode\PX_Objects_AR_ARRegister_extensions.cs(36): error CS0426: The type name 'baccountID' does not exist in the type 'Customer'
\App_RuntimeCode\PX_Objects_AR_ARRegister_extensions.cs(36): error CS0426: The type name 'baccountID' does not exist in the type 'Customer'
Badge +12

Sorry, case again.

 

[PXDefault(typeof(Search<BAccountExt.usrDate_Of_Loss , 
Where<Customer.bAccountID, Equal<Current<ARInvoice.customerID>>>>),
PersistingCheck = PXPersistingCheck.Nothing)]

 

Userlevel 3
Badge

Its not defaulting.  I’m wondering if the problem is the 

[PXFormula(typeof(Default<ARInvoice.CustomerID>))]

which I thought was trying to trigger the default after customerID has changed

Userlevel 3
Badge

I tried to set it to a different field

[PXFormula(typeof(Default<ARInvoice.dueDate>))]

and it still doesn’t work. When I change DueDate the field doesn’t default

 

What I am trying to do is change the value of the user_Date_Of_Loss to the usrDateOfLoss from the Customer screen when the customer is selected.   Should I put this on the change event of the customer or somewhere else????

Userlevel 7
Badge

Hi @edwardmcgovern97 - were you able to find a solution? Thank you!

Userlevel 4
Badge +1

@darylbowman Thank you for the (patient) explanation about case sensitivity - it helped me finish up a customization today!

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