Skip to main content
Solved

Trying to Default a Value using Customization Project?


Forum|alt.badge.img

I’m trying to default Use Customer Account to true or false based on the Shipping Terms via the Fields tab in the Customization Project. I’m using the code “=IIf([ShipTermsID] = 'PPA', False, True)” however, this doesn’t work. How can I get this to work.

Best answer by harutyungevorgyan

kkraus wrote:
harutyungevorgyan wrote:
kkraus wrote:
davidnavasardyan wrote:

Hi ​@kkraus 

If you already have a project you want to add this code to, open it. Otherwise, create a new one.  Within your customization project, click the Code button (typically found in the left panel).  Click Add Source CodeAdd Graph Extension

In the lookup, search for “SOShipmentEntry” .

 

Once you’ve created the extension file, you’ll see a code editor.  Paste in the event handler that ​@harutyungevorgyan  provided. It should look like this: 

 

namespace PX.Objects.SO
{
  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers
      public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
        {
            if (e.Row == null)
                return;

            e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
        }
    #endregion
  }
}

After pasting your code, click Save, then publish your changes.

When it finishes, go back to the SO302000 screen (Shipments) and test by updating the Ship Terms field. Acumatica should then automatically set the Use Customer Account checkbox based on whether you chose “PPA” or not.

That worked perfectly ​@harutyungevorgyan and ​@davidnavasardyan! One final question. If I wanted to turn off Use Customer Account for specific shipping terms instead of turning it on, how would I do that? I presume that I would just need to add another line of :

e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA")

And change a bit, but how would I invert this?

You already have e.NewValue != "PPA" and this part is totally simple, you say that e.NewValue (which is an updated value) is not "PPA". If you have complex conditions, you can ask, and I will give you the right code, but mostly, what you need to do is to use && as (and) and || as (or) and write your condition right after PPA so for example, e.NewValue != "PPA" || e.NewValue != "AAP").

 

@kkraus in addition if you need just reverse same logic you need just write == instead if !=, so you will say that UseCustomerAccount should be checked only if e.NewValue == "PPA"

Makes sense. If I wanted to do a logic loop for two shipping vias that check the Use Customers Account and two that unchecked the box, would I just do e.NewValue != "PPA" || e.NewValue != "AAP" || e.NewValue == "PA" || e.NewValue == "AP"? I tried doing this and it just defaulted to checking the box no matter what.

@kkraus ,
 

Thank you for your continued interest!

At this point, we’re diving into foundational principles of the C# language itself—particularly around boolean logic and condition evaluation. This can get quite deep for what should be a simple question-answer in Acumatica Community.

For your case, the cleanest and most readable way to implement the logic is by using a list and checking inclusion like this:

 

// Define the list of types for which the checkbox should be checked
string[] acceptedTypes = new string[] { "PA", "AP" };

// Check if the new value is in the accepted types list
// Make sure to include 'using System.Linq;' at the top of your file, as it's required for the Contains() method to work
bool useCustomerAccount = acceptedTypes.Contains(e.NewValue);

// Set the checkbox value based on the result
e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, useCustomerAccount);

// If you want to check the checkbox when the value is NOT in the list, use:
// e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, !useCustomerAccount);

You need to paste this code instead of e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != “PPA”); line in your code now.
If this approach is unclear or feels unfamiliar, I’d kindly suggest investing some time into C# basics. You don’t need to master the entire language right away, but knowing how conditionals, arrays, and events work will go a long way in making your Acumatica customizations more reliable and maintainable.

Happy coding! 👨‍💻

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

10 replies

Forum|alt.badge.img+6
  • Captain II
  • 576 replies
  • April 14, 2025

To be clear, you’re not setting up a default value for that field. I’m being picky about the language but it does have a relationship to which events you’ll want to respond to.

PXDefault attribute formulas won’t react, by default, to a change in another field.

PXFormula can react to a change to another field so you could use that to change the value of one field based on the value of another field without writing much code.

You can also write code to facilitate that logic which might be a better way to do it should the value ‘PPD’ ever be changed or new codes added that need that same logic. You also need to consider whether the Use Customer Account can be unchecked after the user selected PPD.

 

 


harutyungevorgyan
Jr Varsity I
Forum|alt.badge.img+1

Hello ​@kkraus ,

 

 

 

I am writing this message from my phone, so please excuse any typos, as I'm coding without a compiler. 😅

 

 

 

I believe the easiest way to achieve your goal is by using Event Handlers. You will need to create a graph extension for `SOShipmentEntry` and implement the `FieldUpdated` event handler for `ShipTermsID` there.

 

 

 

Here’s the code I hope will work on the first attempt. You can either create a new customization package or use an existing one. Go to the Code section, add new code as a Graph Extension, choosing the SO302000 screen from the lookup, and paste the event handler there. After publishing, it should work.

 

public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
{
  if(e.Row == null)
     {
       return;
     }
          e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
}

 

 

Let me know if you have any questions!


Forum|alt.badge.img
  • Author
  • Freshman I
  • 51 replies
  • April 15, 2025
harutyungevorgyan wrote:

Hello ​@kkraus ,

 

 

 

I am writing this message from my phone, so please excuse any typos, as I'm coding without a compiler. 😅

 

 

 

I believe the easiest way to achieve your goal is by using Event Handlers. You will need to create a graph extension for `SOShipmentEntry` and implement the `FieldUpdated` event handler for `ShipTermsID` there.

 

 

 

Here’s the code I hope will work on the first attempt. You can either create a new customization package or use an existing one. Go to the Code section, add new code as a Graph Extension, choosing the SO302000 screen from the lookup, and paste the event handler there. After publishing, it should work.

 

public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
{
  if(e.Row == null)
     {
       return;
     }
          e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
}

 

 

Let me know if you have any questions!

@harutyungevorgyan Thank you for this. I’m having a bit of hard time figuring out how to do the steps you listed. I can find the adding Graph Extension code, but SO302000 isn’t in the list of lookup graphs. Could you provide a bit more of in depth instructions?


davidnavasardyan
Jr Varsity I
Forum|alt.badge.img+3

Hi ​@kkraus 

If you already have a project you want to add this code to, open it. Otherwise, create a new one.  Within your customization project, click the Code button (typically found in the left panel).  Click Add Source CodeAdd Graph Extension

In the lookup, search for “SOShipmentEntry” .

 

Once you’ve created the extension file, you’ll see a code editor.  Paste in the event handler that ​@harutyungevorgyan  provided. It should look like this: 

 

namespace PX.Objects.SO
{
  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers
      public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
        {
            if (e.Row == null)
                return;

            e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
        }
    #endregion
  }
}

After pasting your code, click Save, then  publish your changes.

When it finishes, go back to the SO302000 screen (Shipments) and test by updating the Ship Terms field. Acumatica should then automatically set the Use Customer Account checkbox based on whether you chose “PPA” or not.


harutyungevorgyan
Jr Varsity I
Forum|alt.badge.img+1

Hello @

kkraus wrote:
harutyungevorgyan wrote:

Hello ​@kkraus ,

 

 

 

I am writing this message from my phone, so please excuse any typos, as I'm coding without a compiler. 😅

 

 

 

I believe the easiest way to achieve your goal is by using Event Handlers. You will need to create a graph extension for `SOShipmentEntry` and implement the `FieldUpdated` event handler for `ShipTermsID` there.

 

 

 

Here’s the code I hope will work on the first attempt. You can either create a new customization package or use an existing one. Go to the Code section, add new code as a Graph Extension, choosing the SO302000 screen from the lookup, and paste the event handler there. After publishing, it should work.

 

public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
{
  if(e.Row == null)
     {
       return;
     }
          e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
}

 

 

Let me know if you have any questions!

@harutyungevorgyan Thank you for this. I’m having a bit of hard time figuring out how to do the steps you listed. I can find the adding Graph Extension code, but SO302000 isn’t in the list of lookup graphs. Could you provide a bit more of in depth instructions?

Hello ​@kkraus ,

Sorry, that’s my fault. Actually, in the lookup UI, you need to choose the SOShipmentEntry graph, not the screen.

Feel free to use the attached package, in which I already did the required steps.
 


Forum|alt.badge.img
  • Author
  • Freshman I
  • 51 replies
  • April 15, 2025
davidnavasardyan wrote:

Hi ​@kkraus 

If you already have a project you want to add this code to, open it. Otherwise, create a new one.  Within your customization project, click the Code button (typically found in the left panel).  Click Add Source CodeAdd Graph Extension

In the lookup, search for “SOShipmentEntry” .

 

Once you’ve created the extension file, you’ll see a code editor.  Paste in the event handler that ​@harutyungevorgyan  provided. It should look like this: 

 

namespace PX.Objects.SO
{
  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers
      public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
        {
            if (e.Row == null)
                return;

            e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
        }
    #endregion
  }
}

After pasting your code, click Save, then  publish your changes.

When it finishes, go back to the SO302000 screen (Shipments) and test by updating the Ship Terms field. Acumatica should then automatically set the Use Customer Account checkbox based on whether you chose “PPA” or not.

That worked perfectly ​@harutyungevorgyan and ​@davidnavasardyan! One final question. If I wanted to turn off Use Customer Account for specific shipping terms instead of turning it on, how would I do that? I presume that I would just need to add another line of :

e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA")

and change a bit, but how would I invert this?


harutyungevorgyan
Jr Varsity I
Forum|alt.badge.img+1
kkraus wrote:
davidnavasardyan wrote:

Hi ​@kkraus 

If you already have a project you want to add this code to, open it. Otherwise, create a new one.  Within your customization project, click the Code button (typically found in the left panel).  Click Add Source CodeAdd Graph Extension

In the lookup, search for “SOShipmentEntry” .

 

Once you’ve created the extension file, you’ll see a code editor.  Paste in the event handler that ​@harutyungevorgyan  provided. It should look like this: 

 

namespace PX.Objects.SO
{
  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers
      public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
        {
            if (e.Row == null)
                return;

            e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
        }
    #endregion
  }
}

After pasting your code, click Save, then publish your changes.

When it finishes, go back to the SO302000 screen (Shipments) and test by updating the Ship Terms field. Acumatica should then automatically set the Use Customer Account checkbox based on whether you chose “PPA” or not.

That worked perfectly ​@harutyungevorgyan and ​@davidnavasardyan! One final question. If I wanted to turn off Use Customer Account for specific shipping terms instead of turning it on, how would I do that? I presume that I would just need to add another line of :

e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA")

And change a bit, but how would I invert this?

You already have e.NewValue != "PPA" and this part is totally simple, you say that e.NewValue (which is an updated value) is not "PPA". If you have complex conditions, you can ask, and I will give you the right code, but mostly, what you need to do is to use && as (and) and || as (or) and write your condition right after PPA so for example, e.NewValue != "PPA" || e.NewValue != "AAP").

 

@kkraus in addition if you need just reverse same logic you need just write == instead if !=, so you will say that UseCustomerAccount should be checked only if e.NewValue == "PPA"


Forum|alt.badge.img
  • Author
  • Freshman I
  • 51 replies
  • April 15, 2025
harutyungevorgyan wrote:
kkraus wrote:
davidnavasardyan wrote:

Hi ​@kkraus 

If you already have a project you want to add this code to, open it. Otherwise, create a new one.  Within your customization project, click the Code button (typically found in the left panel).  Click Add Source CodeAdd Graph Extension

In the lookup, search for “SOShipmentEntry” .

 

Once you’ve created the extension file, you’ll see a code editor.  Paste in the event handler that ​@harutyungevorgyan  provided. It should look like this: 

 

namespace PX.Objects.SO
{
  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers
      public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
        {
            if (e.Row == null)
                return;

            e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
        }
    #endregion
  }
}

After pasting your code, click Save, then publish your changes.

When it finishes, go back to the SO302000 screen (Shipments) and test by updating the Ship Terms field. Acumatica should then automatically set the Use Customer Account checkbox based on whether you chose “PPA” or not.

That worked perfectly ​@harutyungevorgyan and ​@davidnavasardyan! One final question. If I wanted to turn off Use Customer Account for specific shipping terms instead of turning it on, how would I do that? I presume that I would just need to add another line of :

e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA")

And change a bit, but how would I invert this?

You already have e.NewValue != "PPA" and this part is totally simple, you say that e.NewValue (which is an updated value) is not "PPA". If you have complex conditions, you can ask, and I will give you the right code, but mostly, what you need to do is to use && as (and) and || as (or) and write your condition right after PPA so for example, e.NewValue != "PPA" || e.NewValue != "AAP").

 

@kkraus in addition if you need just reverse same logic you need just write == instead if !=, so you will say that UseCustomerAccount should be checked only if e.NewValue == "PPA"

Makes sense. If I wanted to do a logic loop for two shipping vias that check the Use Customers Account and two that unchecked the box, would I just do e.NewValue != "PPA" || e.NewValue != "AAP" || e.NewValue == "PA" || e.NewValue == "AP"? I tried doing this and it just defaulted to checking the box no matter what.


harutyungevorgyan
Jr Varsity I
Forum|alt.badge.img+1
kkraus wrote:
harutyungevorgyan wrote:
kkraus wrote:
davidnavasardyan wrote:

Hi ​@kkraus 

If you already have a project you want to add this code to, open it. Otherwise, create a new one.  Within your customization project, click the Code button (typically found in the left panel).  Click Add Source CodeAdd Graph Extension

In the lookup, search for “SOShipmentEntry” .

 

Once you’ve created the extension file, you’ll see a code editor.  Paste in the event handler that ​@harutyungevorgyan  provided. It should look like this: 

 

namespace PX.Objects.SO
{
  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers
      public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
        {
            if (e.Row == null)
                return;

            e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
        }
    #endregion
  }
}

After pasting your code, click Save, then publish your changes.

When it finishes, go back to the SO302000 screen (Shipments) and test by updating the Ship Terms field. Acumatica should then automatically set the Use Customer Account checkbox based on whether you chose “PPA” or not.

That worked perfectly ​@harutyungevorgyan and ​@davidnavasardyan! One final question. If I wanted to turn off Use Customer Account for specific shipping terms instead of turning it on, how would I do that? I presume that I would just need to add another line of :

e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA")

And change a bit, but how would I invert this?

You already have e.NewValue != "PPA" and this part is totally simple, you say that e.NewValue (which is an updated value) is not "PPA". If you have complex conditions, you can ask, and I will give you the right code, but mostly, what you need to do is to use && as (and) and || as (or) and write your condition right after PPA so for example, e.NewValue != "PPA" || e.NewValue != "AAP").

 

@kkraus in addition if you need just reverse same logic you need just write == instead if !=, so you will say that UseCustomerAccount should be checked only if e.NewValue == "PPA"

Makes sense. If I wanted to do a logic loop for two shipping vias that check the Use Customers Account and two that unchecked the box, would I just do e.NewValue != "PPA" || e.NewValue != "AAP" || e.NewValue == "PA" || e.NewValue == "AP"? I tried doing this and it just defaulted to checking the box no matter what.

@kkraus ,
 

Thank you for your continued interest!

At this point, we’re diving into foundational principles of the C# language itself—particularly around boolean logic and condition evaluation. This can get quite deep for what should be a simple question-answer in Acumatica Community.

For your case, the cleanest and most readable way to implement the logic is by using a list and checking inclusion like this:

 

// Define the list of types for which the checkbox should be checked
string[] acceptedTypes = new string[] { "PA", "AP" };

// Check if the new value is in the accepted types list
// Make sure to include 'using System.Linq;' at the top of your file, as it's required for the Contains() method to work
bool useCustomerAccount = acceptedTypes.Contains(e.NewValue);

// Set the checkbox value based on the result
e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, useCustomerAccount);

// If you want to check the checkbox when the value is NOT in the list, use:
// e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, !useCustomerAccount);

You need to paste this code instead of e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != “PPA”); line in your code now.
If this approach is unclear or feels unfamiliar, I’d kindly suggest investing some time into C# basics. You don’t need to master the entire language right away, but knowing how conditionals, arrays, and events work will go a long way in making your Acumatica customizations more reliable and maintainable.

Happy coding! 👨‍💻


Forum|alt.badge.img
  • Author
  • Freshman I
  • 51 replies
  • April 16, 2025
harutyungevorgyan wrote:
kkraus wrote:
harutyungevorgyan wrote:
kkraus wrote:
davidnavasardyan wrote:

Hi ​@kkraus 

If you already have a project you want to add this code to, open it. Otherwise, create a new one.  Within your customization project, click the Code button (typically found in the left panel).  Click Add Source CodeAdd Graph Extension

In the lookup, search for “SOShipmentEntry” .

 

Once you’ve created the extension file, you’ll see a code editor.  Paste in the event handler that ​@harutyungevorgyan  provided. It should look like this: 

 

namespace PX.Objects.SO
{
  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers
      public virtual void _(Events.FieldUpdated<SOShipment.shipTermsID> e)
        {
            if (e.Row == null)
                return;

            e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA");
        }
    #endregion
  }
}

After pasting your code, click Save, then publish your changes.

When it finishes, go back to the SO302000 screen (Shipments) and test by updating the Ship Terms field. Acumatica should then automatically set the Use Customer Account checkbox based on whether you chose “PPA” or not.

That worked perfectly ​@harutyungevorgyan and ​@davidnavasardyan! One final question. If I wanted to turn off Use Customer Account for specific shipping terms instead of turning it on, how would I do that? I presume that I would just need to add another line of :

e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != "PPA")

And change a bit, but how would I invert this?

You already have e.NewValue != "PPA" and this part is totally simple, you say that e.NewValue (which is an updated value) is not "PPA". If you have complex conditions, you can ask, and I will give you the right code, but mostly, what you need to do is to use && as (and) and || as (or) and write your condition right after PPA so for example, e.NewValue != "PPA" || e.NewValue != "AAP").

 

@kkraus in addition if you need just reverse same logic you need just write == instead if !=, so you will say that UseCustomerAccount should be checked only if e.NewValue == "PPA"

Makes sense. If I wanted to do a logic loop for two shipping vias that check the Use Customers Account and two that unchecked the box, would I just do e.NewValue != "PPA" || e.NewValue != "AAP" || e.NewValue == "PA" || e.NewValue == "AP"? I tried doing this and it just defaulted to checking the box no matter what.

@kkraus ,
 

Thank you for your continued interest!

At this point, we’re diving into foundational principles of the C# language itself—particularly around boolean logic and condition evaluation. This can get quite deep for what should be a simple question-answer in Acumatica Community.

For your case, the cleanest and most readable way to implement the logic is by using a list and checking inclusion like this:

 

// Define the list of types for which the checkbox should be checked
string[] acceptedTypes = new string[] { "PA", "AP" };

// Check if the new value is in the accepted types list
// Make sure to include 'using System.Linq;' at the top of your file, as it's required for the Contains() method to work
bool useCustomerAccount = acceptedTypes.Contains(e.NewValue);

// Set the checkbox value based on the result
e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, useCustomerAccount);

// If you want to check the checkbox when the value is NOT in the list, use:
// e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, !useCustomerAccount);

You need to paste this code instead of e.Cache.SetValueExt<SOShipment.useCustomerAccount>(e.Row, e.NewValue != “PPA”); line in your code now.
If this approach is unclear or feels unfamiliar, I’d kindly suggest investing some time into C# basics. You don’t need to master the entire language right away, but knowing how conditionals, arrays, and events work will go a long way in making your Acumatica customizations more reliable and maintainable.

Happy coding! 👨‍💻

This worked. Thanks for all the help!


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