Hi
Thanks for you answers, both of you.
Vaclav, this package is useful but not precisely in that case, since I wish to apply the domain to certain type of fields, depending on their data type, and the object explorer doesn’t show data type.
Lukas, I reused your script, and after few tweak I made it work.
Here is the script I used : (WARNING IT GENERATE LOTS OF LOG, i still need to clean this)
function main()
{
var e, a, Entity, Attribute, aqString, aSubString, Res;
// var Domain = Model.Domains.GetObjectByName(‘Domain1’); //Change name of the Domain here
/* if (Domain == null)
{
Log.Information(‘Domain ‘+Domain+’ does not exist.’)
return;
}*/
Model.Lock();
for (e=0; e<Model.Entities.Count; e++)
{
Entity = Model.Entities.GetObject(e);
Entity.Lock();
for (a=0; a<Entity.Attributes.Count; a++)
{
Log.Information('Check the table '+Entity.Name);
Attribute = Entity.Attributes.GetObject(a);
if (Attribute.DataType!=null)
{
var data_type = Attribute.DataType.Name;
var attribute_name = Attribute.Name;
Log.Information('Check the ‘+attribute_name+’ field of type '+data_type);
var not_sys_table = 0
var Domain = Model.Domains.GetObjectByName(‘Enculer’);
switch (attribute_name) {
case ‘sys_sourcename’ :
var Domain = Model.Domains.GetObjectByName(‘sys_large’);
var text = ‘sys_large’;
break;
default :
var text_att = attribute_name;
var not_sys_table = 1;
Log.Information(‘Have not found ‘+text_att +’ in the system attributes’ ) ;
}
if(not_sys_table == 1)
{
Log.Information('We check the other type of fields ’ +data_type ) ;
switch(data_type) {
case ‘Character varying’:
if(Attribute.DataTypeParam1 <180){
var Domain = Model.Domains.GetObjectByName(‘small text’);
var text = ‘small_text’;
}
else if(Attribute.DataTypeParam1 >1800){
var Domain = Model.Domains.GetObjectByName(‘large text’);
var text = ‘large_text’; }
else {
var Domain = Model.Domains.GetObjectByName(‘medium text’);
var text = ‘medium_text’;
}
break;
case ‘Character varying(%p1)’:
if(Attribute.DataTypeParam1 <180){
var Domain = Model.Domains.GetObjectByName(‘small text’);
var text = ‘small_text’;
}
else if(Attribute.DataTypeParam1 >1800){
var Domain = Model.Domains.GetObjectByName(‘large text’);
var text = ‘large_text’; }
else {
var Domain = Model.Domains.GetObjectByName(‘medium text’);
var text = ‘medium_text’;
}
break;
case ‘Timestamp without time zone’:
var Domain = Model.Domains.GetObjectByName(‘date and time’);
var text = ‘date and time’;
break;
default :
var Domain = Model.Domains.GetObjectByName(‘none existing domain’);
var text_att = Attribute.Name;
var not_sys_table = 1
Log.Information('Have not found in other '+text_att+ 'with type '+Attribute.DataType ) ;
}
}
if (Domain == null)
{
Log.Information(‘Domain ‘+text+’ does not exist.’)
return;
}
Attribute.SetLinkedObject(‘DataType’, null);
Attribute.ChangeDataType(Domain);
}
}
Entity.UnLock();
}
Model.UnLock();
}
It take a little bit of time, and you may wish to change the rules to apply the different domain but it works.
One issue, if there is a attribute he can’t change, the function will stop and will leave your model and entities locked, you may need to use a othe piece of code to unlock them. (since I don’t know how to do it manually)