field automatically filled

I have created a quantity field for a sample quantity within an opportunity. I would like this field to be automatically filled with the word "standard" if no quantity is entered. How can I do that?

Thank you very much!!

Tim

Parents
  • You may have a problem with the data type, a quantity is a number, usually an integer, while the word "standard" is not a number at all.

    I assume you want to use "standard" because it's not really a set number but rather it's dependent on the product or other parameter in your Opportunity

    As always there are multiple ways you could address this, I can think of four:

    1. Use an Integer field, leverage the controller to set the "standard" value, whatever that may be, when the product is added:
      • set the "Default Value" to 0 in the definition of the sample_quantity field in Studio
      • in the create controller set up an on-change event on the field that dictates the standard quantity, for example the product.
      • When the product changes, if the sample quantity is zero, calculate the standard for the exact product and populate the standard quantity field. Don't do anything if the standard quantity is already non-zero.
      • The user can still override the quantity to something other than the default setting.
      • You will need some more checks and balances in case the user changes the quantity back to zero (inline edit, list view edit, editing in the preview pane etc..)
    2. Use an Integer field, interpret 0 as standard and update the sample quantity in an on-save logic hook
      1. similar to #1 you set a default value of 0
      2. add a hint that 0 will be replaced with standard quantity on save
      3. on save add a Confirmation alert that, if the quantity is zero, asks to the user to confirm that they want the quantity to be defaulted for them.
      4. in a before save logic hook check the sample quantity, if zero, then change the quantity to what it needs to be.
    3. Use an Integer field, leverage the studio settings to tell people what 0 really means
      • set the "Default Value" to 0 in the definition of the sample_quantity field in Studio
      • add "Help Text" in studio that essentially says: zero = standard quantity
    4. Use a text field (I am not a fan of this option)
      • in Studio set the "Default Value" to "standard" 
      • the user can still override that default.

    Personally, I would go for #2 to have improved reporting and actual quantities assuming you have logic to decide what "standard" means. The before save will trigger regardless of the view, so you are covered wherever they can edit those values. I would even take it a step further adding a "standard sample quantity" to the product catalog (assuming it's product you are going by) so you can do a lookup to populate the standard quantity instead of hardcoding product in your controller logic.

    FrancescaS

    (apologies for the many edits on this post, ideas came as I re-read after posting...)

Reply
  • You may have a problem with the data type, a quantity is a number, usually an integer, while the word "standard" is not a number at all.

    I assume you want to use "standard" because it's not really a set number but rather it's dependent on the product or other parameter in your Opportunity

    As always there are multiple ways you could address this, I can think of four:

    1. Use an Integer field, leverage the controller to set the "standard" value, whatever that may be, when the product is added:
      • set the "Default Value" to 0 in the definition of the sample_quantity field in Studio
      • in the create controller set up an on-change event on the field that dictates the standard quantity, for example the product.
      • When the product changes, if the sample quantity is zero, calculate the standard for the exact product and populate the standard quantity field. Don't do anything if the standard quantity is already non-zero.
      • The user can still override the quantity to something other than the default setting.
      • You will need some more checks and balances in case the user changes the quantity back to zero (inline edit, list view edit, editing in the preview pane etc..)
    2. Use an Integer field, interpret 0 as standard and update the sample quantity in an on-save logic hook
      1. similar to #1 you set a default value of 0
      2. add a hint that 0 will be replaced with standard quantity on save
      3. on save add a Confirmation alert that, if the quantity is zero, asks to the user to confirm that they want the quantity to be defaulted for them.
      4. in a before save logic hook check the sample quantity, if zero, then change the quantity to what it needs to be.
    3. Use an Integer field, leverage the studio settings to tell people what 0 really means
      • set the "Default Value" to 0 in the definition of the sample_quantity field in Studio
      • add "Help Text" in studio that essentially says: zero = standard quantity
    4. Use a text field (I am not a fan of this option)
      • in Studio set the "Default Value" to "standard" 
      • the user can still override that default.

    Personally, I would go for #2 to have improved reporting and actual quantities assuming you have logic to decide what "standard" means. The before save will trigger regardless of the view, so you are covered wherever they can edit those values. I would even take it a step further adding a "standard sample quantity" to the product catalog (assuming it's product you are going by) so you can do a lookup to populate the standard quantity instead of hardcoding product in your controller logic.

    FrancescaS

    (apologies for the many edits on this post, ideas came as I re-read after posting...)

Children
  •  Francesca lays out a good set of suggestions on how to approach your problem. One additional option to consider is the following:

    • Leave Quantity as an integer field so you can ensure the values are numeric
    • Create a second field that is a calculated field evaluating whether Quantity is populated or not. The field would have a formula like the following:
      ifElse(
          equal(
              $quantity,
              ""
          ),
          "Standard",
          "Non-Standard"
      )

    The benefits of this option include:

    • The second field can be displayed on the layout so that the users responsible for adjusting the quantity can confirm whether it should be standard or not
    • The second field gives you an easily reportable field to group results
    • If 0 is a valid sample quantity, it doesn't require changing any business process or training to accommodate a special case

    Chris