Hi All,
Can you please help me to remove an object from Database through script? I have written a script using "Remove" function and it is removing the objects from the model.
However if I go to "Explorer" window I can see still the objects are lying in the folder but not in the model diagram. Does anyone faced this kind of issue? Below is the code snippet.Thanks in advance.
var documents = models.ObjOccListFilter(Constants.OT_INFO_CARR);
if(documents)
{
for(k = 0; k <= (documents.length-1); k++)
{
var lstDoc = documents[k];
if((lstDoc.getSymbol()==892)||(lstDoc.getSymbol()==1649)||(lstDoc.getSymbol()==1650))
{
lstDoc.Remove();
}
}
}Best Regards,
Srinivas.
Christoph Reitenberger on
Hello Srinivas,
as you mentioned, you are only deleting the occurence in the model.
You need to delete the object definition in your database.
To do that, you have to select the object definition of your occurence by e.g.:
var oMyObjectToDelete = mylstDoc.ObjDef();
The delete an Item/object definition method is in:
Report class Group - Method Delete
Delete ( Item ItemToDelete )
So you have to get the group, your object definition is in via e.g.:
var gMyObjectToDeleteGroup = oMyObjectToDelete.Group();
Then you can use the method above:
gMyObjectToDeleteGroup.Delete(oMyObjectToDelete);
Be very careful running this method by script, tho! ;)
Instead of initiating your if-clause with if(documents), i would rather use if(documents.length>0).
And to make double sure, you delete the correct object, you can use the GUID method to identify your objects.. (ObjDef.GUID(), the GUID-method is inherited in any Item)
Regards
Christoph