How to delete an item from a production by code?

Primary tabs

This is the translation of the original question.

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




Maybe just a mistake in the production variable name:

set productionName = "MyApp.production"
if ##class(Ens.Config.Item).NameExists(produccionName,itemDelete, .idItem)

Hi Francisco,

Have you tried using the RemoveItem() method on the Ens.Config.Production class?

Hi Francisco,

%Delete needs an argument, just use %DeleteId(idItem) and it should work. You even don't need to open the item as %Delete and %DeleteId are class methods.

Hi Francisco,

What you need is:

set prod=##class(Ens.Config.Production).%OpenId(productionName)

do prod.RemoveItem(objItem)

do prod. %Save()

it is a mistake when I've copied it in the post. The original code is the same name, and I get the idItem, thanks

Yes I have,

but it doesn't work, the item is removed from database but it still into production.cls, so the production is unestable. I should to remove the item manually.

Interesting, I'm sure I've had this working in the past. I will have a hack around with it. What version are you using?

Cache for Windows (x86-64) 2017.2.1 (Build 801_3U) Thu Apr 12 2018 10:02:23 EDT

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.

Exactly... using %Save aftewards RemoveItem in Ens.Config.Production works

Thanks for all