Format choice list using g_form.addoption

Sheryl Lyke1
Kilo Contributor

In a client script, I'm using g_form.addOption to populate a choice list dependent on another choice chosen on the form. My problem is I want to format the choices to make them more easily readable. The choices are coming from a table and are formatted as long. They're showing without commas making it very difficult to read.   See below

find_real_file.png

I've seen that you can change the attributes of a field to format=none to exclude commas but how would I format the list to include them.

Here's the code:

var limit = new GlideRecord('u_ap_doa_expense_type_limits');  

     

      limit.addQuery('u_exp_type_id',exp.u_exp_type_id);  

      limit.orderBy('u_exp_type_limit');

      limit.query();

      while(limit.next()) {  

      var limitamt=parseInt(limit.u_exp_type_limit);

      g_form.addOption('u_auth_lim', limitamt, limitamt);  

    }

Any help is much appreciated!!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Here's one method I found. Write yourself a little function that does a RegEx on a string representation and use that as the display value (third parameter.)



function numberWithCommas(x) {
   
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}


View solution in original post

2 REPLIES 2

Chuck Tomasi
Tera Patron

Here's one method I found. Write yourself a little function that does a RegEx on a string representation and use that as the display value (third parameter.)



function numberWithCommas(x) {
   
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}


Thank you!!! Worked perfectly