Why can't I set decimals in a decimal field?

e_wilber
Tera Guru

I have a custom decimal field that I'm trying to update via a business rule:

        met.u_total_value = 4.25;
        met.update();
 
It's updating the field to 4 instead of keeping the decimals. Why is my decimal disappearing and how do I keep it?
7 REPLIES 7

@e_wilber 

share the dictionary screenshot of that field.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Vishal Jaswal
Giga Sage

Hello @e_wilber 

Screenshot of u_total_value dictionary:

VishalJaswal_0-1744033712417.png


Before:

VishalJaswal_1-1744033737031.png



After your code executed in Scripts - Background:

var grInc = new GlideRecord('incident');
grInc.get('ed92e8d173d023002728660c4cf6a7bc');
var tst = 4.25;
grInc.u_total_value = parseFloat(tst.toFixed(2));
grInc.update();

VishalJaswal_2-1744033762382.png

 

VishalJaswal_3-1744033769994.png

 


Hope that helps!

Dharma Liyanage
Tera Guru

@e_wilber 

I do this in Catalog requests  & platform forms.

1. Platform UI

    Type = Price
2. Attributes
    edge_encryption_enabled=true,omit_sys_original=true,serializer=com.glide.script.PriceXMLSerializer
3. After update : 
Estimated Total Project Amount   $
DharmaLiyanage_0-1744034776753.png

 

 
In Catalog
1. Type = Single Line Text
2. Check the values are getting set    
var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((cs.match(letter))) {
var value = Math.round(cs*1000)/1000; // 10 defines 1 decimals, 100 for 2, 1000 for 3
}
else {
return false;
}
3; in the workflow
    var cost_if_known =     parseFloat(current.variables.cost.toString());
 
Both works for me!!