Symbol to be appended to a field

srivatsa
Giga Contributor

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.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

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.

find_real_file.png 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.

find_real_file.png 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);

 

View solution in original post

5 REPLIES 5

Thank You!