How to Add Comma Formatting to Field with Data Type of Long

Michael Zglesze
Giga Expert

Hello Community!

I'm building a new CI Class for Network Circuits, and for the Access Circuit Size field, the customer would like to see the value is bits per second (bps).  If I were to make that field an Integer data type, then the largest value I could put there would be 10,000,000,000 (10 Gbps).  In the future, if we ever need to put anything bigger than that, we won't be able to, so I've decided to make the data type of the field Long.  Now I can store 100,000,000,000 (100 Gpbs), but there's no longer any autoformatting with commas, making it hard for the eyeballs to quickly determine the value.

I see a metric boatload of articles in the Community about how to remove commas from an Integer field using format=none in the Attribute field of the Dictionary entry, but nothing about adding commas to a Long field.

Has anyone added comma formating to a Long field?  Is there maybe some "format" attribute that I can use to do it?

Thank you!

Michael Zgleszewski

1 ACCEPTED SOLUTION

Michael Zglesze
Giga Expert

Sweet!  I did some reading, but my attempt at using Transformations failed.  BUT...I did figure out how to accomplish a slightly larger value!  Here's what I did:

  1. Because "long" wasn't listed as a Field Type under Field Normalization, I created a new one for it.
  2. When I attempted to create a new Transformation, the field I wanted wasn't listed.  I did some more reading and learned this is because only Integer and String fields are available for Transformation.  😞
  3. Then, I decided to try a Decimal data type field, and that allowed 100,000,000,000 to be entered, AND automatically put the commas in!  It turns out it will take up to 10,000,000,000,000!  🙂
  4. In the Dictionary record for my field, I added "scale=0" as a Attribute, so if someone does enter a decimal number, it will strip it off and make it a whole number.

Using a Decimal data type field in conjunction with the "scale=0" Attribute was able to allow me to put up to 10 Tbps as a value, which in real life in 2020 would be phenomenal (and expensive!) for a Network Circuit.

Thank you for your help, Javier!  It may not have worked as planned, but it led me to the correct answer! 

View solution in original post

4 REPLIES 4

Javier Arroyo
Kilo Guru

Would a field transformation work using a regex?

this works with a script:
var transformed = "1000000000".replace( /\d{1,3}(?=(\d{3})+(?!\d))/g , "$&,");
gs.debug(transformed);

Michael Zglesze
Giga Expert

I can try that...is that a Client Script?  Give me a little more explanation on where to put that, and I can test it out.  Thanks!  🙂

Field Normalization & Transformation is an OOTB feature.
https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/field-administration/concept/c_FieldNormalization.html

A Client Script would limit the behavior to front-end.
A Business Rule would cover it all.

But, those two are more invasive than a normalization solution which can be categorized as configuration 

Michael Zglesze
Giga Expert

Sweet!  I did some reading, but my attempt at using Transformations failed.  BUT...I did figure out how to accomplish a slightly larger value!  Here's what I did:

  1. Because "long" wasn't listed as a Field Type under Field Normalization, I created a new one for it.
  2. When I attempted to create a new Transformation, the field I wanted wasn't listed.  I did some more reading and learned this is because only Integer and String fields are available for Transformation.  😞
  3. Then, I decided to try a Decimal data type field, and that allowed 100,000,000,000 to be entered, AND automatically put the commas in!  It turns out it will take up to 10,000,000,000,000!  🙂
  4. In the Dictionary record for my field, I added "scale=0" as a Attribute, so if someone does enter a decimal number, it will strip it off and make it a whole number.

Using a Decimal data type field in conjunction with the "scale=0" Attribute was able to allow me to put up to 10 Tbps as a value, which in real life in 2020 would be phenomenal (and expensive!) for a Network Circuit.

Thank you for your help, Javier!  It may not have worked as planned, but it led me to the correct answer!