Skip to main content
Question

Default Field Values


Forum|alt.badge.img+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

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3375 replies
  • June 21, 2021

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


Forum|alt.badge.img+2
  • Author
  • Semi-Pro I
  • 122 replies
  • June 21, 2021
Naveen B wrote:

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.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3375 replies
  • October 24, 2021

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


Forum|alt.badge.img+2
  • Author
  • Semi-Pro I
  • 122 replies
  • January 25, 2022
Naveen B wrote:

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?


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2525 replies
  • January 27, 2022

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


Samvel Petrosov
Jr Varsity I
Forum|alt.badge.img+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;

 

 

 

 

 


Forum|alt.badge.img+2
  • Author
  • Semi-Pro I
  • 122 replies
  • January 27, 2022

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


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