- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2020 11:38 AM
Hi,
I have a requirement where i have to append the dollar symbol on a decimal field. I cannot use a currency field due to certain restrictions.
The dollar should be ever present on the field, ie on load and even when the value is entered in the field, it should be saved with the dollar symbol.
Please suggest what can be done,
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2020 01:26 PM
This is what I did for a similar requirement.
First I created a field with the Type of String on the table, and put $ as the Default Value.
This makes it so that $ is displayed in the field when the New button is clicked to display the otherwise empty form.
Next I created a Business Rule on this table that runs Before Insert and Update with no Filter Conditions.
The script in the BR ensures that record is saved with the first character always a $, and it will also validate that the rest of the field contains a numeric value, forced to 2 decimal places if necessary. Note that in my requirement, Amount is not mandatory, so saving a record empty or with just the $ is valid. If you require an Amount, just remove the first if line (and corresponding closing bracket)
(function executeRule(current, previous /*null when async*/) {
if(current.u_amount != '' && current.u_amount != '$'){
var amt = parseFloat(current.u_amount.replace('$', '')).toFixed(2);
if(amt == 'NaN'){
gs.addInfoMessage('Please enter a valid Amount');
current.setAbortAction(true);
}
else{
current.u_amount = '$' + amt;
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2020 09:06 PM
Thank You!