The CreatorCon Call for Content is officially open! Get started here.

Is it possible to change a Field Type from Decimal to Integer?

richelle_pivec
Mega Guru

Is it possible to change a Field Type from Decimal to Integer? It does not appear to be a choice when I click on the magnifying glass next to the Type for an existing "decimal" field.

thanks,

Richelle

1 ACCEPTED SOLUTION

Chandu Telu
Tera Guru

Hi Richelle,

 

No, you can;t change the Field Type from Decimal to Integer it will through an error

View solution in original post

10 REPLIES 10

I thought I saw something recently, but a quick search through the docs and HI KB didn't turn up anything. If I come across it again, I'll be sure to share.

If you're in a bit of a hurry, reach out to customer support to see if they know of something published (and post the link back here). Thanks.

Hi Chuck,

Is it the same case with Integer to Decimal? I have a custom field which is of Integer type and I want to change the type to Decimal.

Thanks,

Vaishnavi

richelle_pivec
Mega Guru

Thank you both for your replies. Fortunately, this is in our Dev instance and a newly created field on a newly created table. So, no harm to just add a different field an move on.

I'll do a little investigation first to see if the script I'm trying to do would work with a decimal field. It isn't working yet, but I can't imagine why it would not. I'm trying to sum all of the values in the child tasks (in one field) into a field on the parent. I found a script that appears to be using integers, so I figured I needed to use integers too. But maybe I'll poke around a little and see if it couldn't be done with decimals instead.

Thanks,

Richelle

If you like, share the script and we take a look. 

One thing I found when doing "summing" like this is to follow two basic rules:

  1. getValue() is your friend.
  2. Never assume the data type and cast it to what you need.

Example
Bad code:

var num = 0;

while (something happens to be true here) {
  num += gr.u_count;
}

Good code:

var num = 0;

while (another true condition) {
   var countVal = gr.getValue('u_count');
   num += parseInt(countVal, 10);
}

richelle_pivec
Mega Guru

Thanks Chuck,

This is where I got the original script (and permission to use it):

Business rule script to count value on related list

I modified it like this:

Name: Estimated Implementation Cost

Table: Demand Task [u_demand_task]

Run at: Server

When to Run: Update

Script:

(function executeRule(current, previous /*null when async*/) {


 var additional = new GlideAggregate('u_demand_task');
 additional.addQuery('approval', 'Approved');
 additional.addQuery('parent',current.sys_id);
 additional.addAggregate('SUM','u_estimated_implementation_cost');
 additional.setGroup(false);
 additional.query();

 if(additional.next())
 gs.log (additional.addAggregate('SUM','u_estimated_implementation_cost'));
 current.u_capital_implementation_cost = additional.getAggregate('SUM','u_estimated_implementation_cost');


current.update();


})(current, previous);

Both u_estimated_implementation_cost (which is on the u_demand_task table) and u_capital_implementation_cost (which is on the dmn_demand table) are decimal field types. (I also tried the business rule on the dmn_demand table as I wasn't quite sure which of the two it belonged on.

thanks for having a look,

Richelle