Written by

Project Manager & Head of Interoperability at Salutic Soluciones, S.L.
Question Kurro Lopez · 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

Comments

Sean Connelly · May 22, 2019

Hi Francisco,

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

0
Kurro Lopez  May 22, 2019 to Sean Connelly

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.

0
Kurro Lopez  May 23, 2019 to Karin Schatz-Cairoli

Yep, I've used DeleteId(idItem) also, and it doesn't work

0
Kurro Lopez  May 23, 2019 to Yuval Golan

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

0
Sean Connelly  May 22, 2019 to Kurro Lopez

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?

0
Kurro Lopez  May 22, 2019 to Sean Connelly

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

0
Sean Connelly  May 22, 2019 to Kurro Lopez

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.

0
Kurro Lopez  May 23, 2019 to Sean Connelly

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

Thanks for all

0
Karin Schatz-Cairoli · May 23, 2019

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.

0
Yuval Golan · May 23, 2019

Maybe just a mistake in the production variable name:

set productionName = "MyApp.production"
if ##class(Ens.Config.Item).NameExists(produccionName,itemDelete, .idItem)
0
Karin Schatz-Cairoli · May 23, 2019

Hi Francisco,

What you need is:

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

do prod.RemoveItem(objItem)

do prod. %Save()

0