Question

Default Field Values

  • 21 June 2021
  • 7 replies
  • 1231 views

Userlevel 5
Badge +2

I am not a programmer but I play one at work.

I have been trying to enter some default field values for our Business Account, Customer & Vendor Forms (CR303000, CR303010, AP303000, AP303010, AR303000, AR303020). Most of the fields are in the shipping tab. I keep running into different errors and have not been successful in accomplishing what I would like to do.

I have created custom projects and set the Attributes of the fields to append.

I’m able to enter [PXDefault(“UPS GND”)] and [PXDefault(“Main”). However when I edit an existing account(vendor/customer) I receive an error that states the field(s) cannot be blank. They are not blank but I’m not sure if I’m seeing this because of the way Business/Customer/Vendor accounts are related and may or may not exist in all three places.

I’ve also tried with no change in result.

 [PXDefault("COMPCAL")]
[PXCustomizeBaseAttribute(typeof(PXDefaultAttribute), "PersistingCheck", PXPersistingCheck.Nothing)]

Some of the Attributes will accept something like [PXDefault(INSite.Main)] but I can’t figure out what to enter on some of them without getting a validation error.

 I’ve tried just locations, both main account and locations and just main account all resulted in error messages.

The fields are, VCarrierID, VFOBPointID, VLeadTime, VSiteID, VShipTermsID, CCarrierID, CFOBPointID, CLeadTime, CSiteID, CShipTermsID, CPriceClassID

Since these are almost all all pulling from other tables, can anyone help me out with the correct template to use? If each of these is difference, how do I figure out what to enter?


7 replies

Userlevel 7
Badge +17

Hi @amajors  Can you please share the code, the one which you have tried on this

Userlevel 5
Badge +2

Hi @amajors  Can you please share the code, the one which you have tried on this

 

Project with Defaults
Attributes changed for field
Attributes changed for field
Attributes changed for field
Error message when editing an existing vendor
New Vendor - All defaults good. Able to enter info and save.

 

I have exported all the Business, Customer & Vendor accounts, updated blank fields and imported back into the system. Still is giving me the error.

Userlevel 7
Badge +17

Hi @amajors If this issue NOT resolved,  have you tried by giving Default Value in the CacheAttached event for that filed in the Graph.

Userlevel 5
Badge +2

Hi @amajors If this issue NOT resolved,  have you tried by giving Default Value in the CacheAttached event for that filed in the Graph.

I don’t know what you are talking about. Where is CacheAttached event?

Userlevel 7
Badge

Hi @Naveen B can you show @amajors where this is? Thanks!

Userlevel 4
Badge +1

Hi @amajors, the PXDefault attribute works only for the new records, for existing records it is not being invoked and basically never work. We usually create a plugin to populate the values for the new fields on the existing records which literally goes over all the records and changes NULL to whatever value we want.

The concept of the Customization Plugin is explained here

 

The typical example of the plugin will be something like below:

    public class MyPlugin: CustomizationPlugin
{
//This method is executed after the customization has been published and the website is restarted.
public override void UpdateDatabase()
{
var soOrderEntry = PXGraph.CreateInstance<SOOrderEntry>();
foreach (SOOrder soOrder in PXSelect<SOOrder>.Select(soOrderEntry))
{
soOrder.CstField = soOrder.CstField ?? "DEFAULT_VALUE";
soOrderEntry.Document.Update(soOrder);
soOrderEntry.Save.PressButton();
}
}
}

 

Another approach to do this will be include a SQL script in the customization package which will update the records with NULL to default values, like below

update SOOrder
set UsrTest ='Test2'
where UsrTest is null;

 

 

 

 

 

Userlevel 5
Badge +2

Thanks @samvellaHBl7QVBU6C6KqXsC79Q but you’ve gone beyond my abilities at this point. If I’m reading what you're saying correctly I thought I did the same thing by exporting, changing the value and then importing. All my data should be there.

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