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
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:
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...)
Tim Hoffmann Francesca lays out a good set of suggestions on how to approach your problem. One additional option to consider is the following:
ifElse( equal( $quantity, "" ), "Standard", "Non-Standard" )
The benefits of this option include:
Chris
Good point Chris Raffle 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