Toad World® Forums

Can't Set Attribute Domain in LER Model via JS script

Hi I have a javascript script in which I wish to propogate the parent attributes to the child.

In the script I am attempting to either migrate the datatype or the domain, depending on which exists;

The code I have written is as follows;

          //Create the Child Attribute and the the properties of the attribute.
          ChildAttribute             = ChildEntity.CreateNewObject(4007);
          ChildAttribute.Name        = Attribute.Name; 
          ChildAttribute.Caption     = Attribute.Name;  
          
          if ( DataType !== null ) { 
             ChildAttribute.Datatype = DataType;
             ChildAttribute.DataTypeParam1 = DataPrecision1;
             ChildAttribute.DataTypeParam2 = DataPrecision2;
          } else { 
             Log.Information("Domain for "+Attribute.Name+" Domain = "+Attribute.Domain.Name);
             ChildAttribute.Domain = Attribute.Domain
          } 

I can clearly see the domain in the log.information. However the ChildAttribute.Domain is not getting populate. Could anyone has it a guess as to what I might be doing wrong?

Its one of the last and final thing I need for the script to work as desired.

Hi Sandy,
please use method ChildAttr.ChangeDataType() instead assign to Domain. So your script will be

...
  if ( DataType !== null ) {
    DTorDomain = DataType
  } else {
    DTorDomain = Domain;
  }
 
  ChildAttribute.ChangeDataType(DTorDomain);
...

When you set only Domain, there is still value of DataType, that should be null when Domain is set.

Regards
Daril

2 Likes