Hi,
I am using a script to create entities/attributes from csv files. The entities are getting created with appropriate attributes. But on clicking edit attribute exception is thrown “Access violation at address 00F38D40 in module ‘TDM.exe’. Read of address 00000000.” . This happens with any other attribute which does not have the same datatype as the first attribute. The problem does not come up for the first attribute.
The code used to add attributes is as follows
function AddAttributes(datastr,ename)
{
var Entity, Attribute, Datatype,param1,param2,AttrCheck;
var DataType_Bigint = Model.ModelDef.DataTypes.GetObjectByName(“Bigint”);
var DataType_Char = Model.ModelDef.DataTypes.GetObjectByName(“VarChar(%p1)”);
var DataType_Boolean = Model.ModelDef.DataTypes.GetObjectByName(“Boolean”);
var DataType_Number = Model.ModelDef.DataTypes.GetObjectByName(“Decimal(%p1, %p2)”);
var DataType_DateTime = Model.ModelDef.DataTypes.GetObjectByName(“DateTime”);
var DataType_Integer = Model.ModelDef.DataTypes.GetObjectByName(“Integer”);
var DataType_SmallInt = Model.ModelDef.DataTypes.GetObjectByName(“SmallInt”);
if(datastr[1]=="") return;
Datatype=null;
param1=null;
param2=null;
if(datastr[3].toUpperCase()==“UNIQUEIDENTIFIER”) Datatype=DataType_Bigint;
if(datastr[3].toUpperCase()==“BIGINT” || datastr[3].toUpperCase()==“INT”) Datatype=DataType_Integer;
if(datastr[3].toUpperCase()==“BIT”) Datatype=DataType_Boolean;
if(datastr[3].toUpperCase()==“SMALLINT”) Datatype=DataType_SmallInt;
if(datastr[3].toUpperCase()==“DATE” || datastr[3].toUpperCase()==“DATETIME”) Datatype=DataType_DateTime;
if(datastr[3].substring(0,8).toUpperCase()==“NVARCHAR” || datastr[3].substring(0,7).toUpperCase()==“VARCHAR” || datastr[3].substring(0,4).toUpperCase()==“CHAR”)
{
Datatype=DataType_Char;
param1= datastr[3].substring((datastr[3].indexOf(’(’))+1,(datastr[3].indexOf(’)’)));
}
if(datastr[3].substring(0,7).toUpperCase()==“DECIMAL” || datastr[3].substring(0,7).toUpperCase()==“NUMERIC” || datastr[3].substring(0,6).toUpperCase()==“NUMBER”)
{
Datatype=DataType_Number;
param1= datastr[3].substring((datastr[3].indexOf(’(’))+1,(datastr[3].indexOf(’,’)));
param2= datastr[3].substring((datastr[3].indexOf(’,’))+1,(datastr[3].indexOf(’)’)));
}
Entity = Model.Entities.GetObjectByName(ename);
Attribute=Entity.Attributes.GetObjectByName(datastr[1]);
if(Attribute==null)
{
Attribute = Entity.CreateNewObject( 4007 );
Attribute.Name = datastr[1];
Attribute.Caption = datastr[1];
Attribute.Description=datastr[2];
Attribute.SetLinkedObject(“DataType”, Datatype);
if(param1!=null)
{
Attribute.DataTypeParam1 =param1;
if(param2!=null) Attribute.DataTypeParam2 =param2;
}
if(datastr[4].toUpperCase()==‘Y’) Attribute.Mandatory=true;
if(datastr[5].toUpperCase()==‘Y’)
{
//var PK=Entity.KeyItems
}
}
}
Thanks in advance.