Changing datatypes

Hi,

I’m working on a project where the customer would like all number-like datatypes (int, float, decimal, etc) changed to a Numeric(38,X), retaining precision and scale, where neccesary. For example(s):

Decimal(19,4) --> Numeric(38,4)
Int --> Numeric(38,0)

I’m able to grab the object:
var NumericDataType = Model.ModelDef.DataTypes.GetObjectByName(“Numeric(%p1,%p2)”);

But, I can’t figure out how to grab the precision (or add precision where necessary). I thought the following would work, but it’s proving not to:

      Attribute.DataTypeParam1 = 38;
      Attribute.DataTypeParam2 = 0;
      Attribute.SetLinkedObject("DataType", NumericDataType);

I only included what was relevant to the discussion. I’m mostly interested to know how you can influence precision and scale in this activity. Again, my code doesn’t throw an error, but it also doesn’t provide the precision and scale.

Please help!

Thanks,

Message was edited by: BriEli

Hi,

I’ll reply on Monday. Thank you for your patience.

Vaclav

Hey Vaclav.

I’ve looked at other areas of the forum (actually just a few posts ago in this category), and it looks like this is entirely possible, but for some reason, I’m NULLING out the precision/scale by doing this.

I’m up against a hard deadline today. If you can give me a little cheese to nibble on until Monday, I’d be most grateful.

Thanks!

Hi,

I tried to use single apostrophes and it worked :slight_smile:

Script:

function main()
{
var Entity, Attribute, e, a;

var DataType_Num = Model.ModelDef.DataTypes.GetObjectByName(“Numeric(%p1,%p2)”);

if (DataType_Num == null)
{
return;
}

Model.Lock();
for (e=0; e<Model.Entities.Count; e++)
{
Entity = Model.Entities.GetObject(e);
Entity.Lock();
Log.Information("Entity: “+Entity.Name);
for (a=0; a<Entity.Attributes.Count; a++)
{
Attribute = Entity.Attributes.GetObject(a);
if (Attribute.DataType != null)
Log.Information(”–current datatype name: "+Attribute.DataType.Name);
if (Attribute.DataType.Name == “Decimal(%p1,%p2)”)
{
Attribute.SetLinkedObject(“DataType”, DataType_Num);
Attribute.DataTypeParam1 = ‘38’;
Attribute.DataTypeParam2 = ‘0’;
Log.Information(“Attribute “+Attribute.Name+” in entity “+Entity.Name+” changed.”);
}
}
Entity.UnLock();
}
Model.UnLock();
}

Good luck,

Vaclav

You beat me to the post. I had found the same thing with double quotes. Thank you so much for your quick response.

This stuff is a lot of fun!

You are welcome and THANKS. It’s nice to see scripting in action :slight_smile:

Vaclav