Question
· May 22, 2019

How to delete an item from a production by code?

Hi all,

I am trying to delete an item from a production through a routine that installs and disables items.

To add any item, I have no problems, even to enable and disable some particular items.

The problem arises when I try to eliminate the production item, because when it does, the production become unstable and only works again when this item is added again in the collection (or the item is deleted manually in the production.cls)

 

This is my code attempt:

set productionName = "MyApp.production"

set itemDelete="MyApp.BP.item"

if ##class(Ens.Config.Item).NameExists(produccionName,itemDelete, .idItem)
{
    write !,"Removing BP: "_itemDelete
    set objItem=##class(Ens.Config.Item).%OpenId(idItem)
    do objItem.%Delete()
    kill objItem

    do ##class(Ens.Director).RestartProduction(0,1)
}


In the best case, it does do nothing and the item is maintained. I have also tried using the %DeleteId() method directly and some functions of the Ens.Config.Production class such as RemoveItem

Any ideas?

 

Best regards,

Francisco López

Discussion (11)3
Log in or sign up to continue

I think the problem is that the RemoveItem() method does not action a %Save() on the production, so the item gets deleted, but remains referenced in the production XML.

If you look at the DeleteConfigItem() in the EnsPortal.ProductionConfig class you will see it calls the RemoveItem() method, but then does a %Save() afterwards to commit it.

I think I must have been doing something similar. I also seem to remember programmatically stopping the production first and then restarting it to remove any memory problems, although I think this was only causing problems on an early version of Ensemble.