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

  • 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...)

  •  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

  • Good point  I like the visual of being able to see if the quantity is standard or not.

    The only scenario not covered is if the number entered in the quantity is by chance the same as the "standard".
    For example, if the standard is 10, and I enter 10, the formula would still result in a "non-standard" label. That's easily solved within if there is only ONE standard quantity and it's not dependent on other factors. It gets a bit more complicated if there is logic behind the standard quantity, for example if the standard quantity is by product or type of Opportunity etc..

    Also, my examples where I assume that 0 is the standard quantity is flawed.
    What if the customer does not want any samples? 0 should indicate none, while using null as the standard as you suggested is a better choice. But then the user still needs to know that blank means standard and they need to change it to 0 for none (or vice versa)... 

    I thought of another option, but it still has a lot of logic involved to make sure you can't have a "non standard" quantity type and a standard quantity... 

    What if the user was able to set the quantity_type dropdown: standard/non-standard.

    The quantity_type defaults to non-standard, the quantity field defaults to zero (no samples).

    If the quantity_type is changed to standard the quantity_field becomes read-only and is then populated by the logic hook (by setting it read-only you avoid the user overriding the quantity while the type is standard and creating a discrepancy)

    If the quantity_type is changed to non-standard by the user, the quantity field is cleared, becomes editable and required. An on change event on the quantity checks if it's standard and alerts the user with a Confirmation alert to let them know they chose the standard quantity and asking them to confirm they want the standard. If confirmed, the system will override the quantity_type and set it to standard.

    Overthinking it?

    Francesca