How to clone an object (Purchase Doc)

2

I needed to use this functionality, but in the purchasing module. I'm not in the Editor, but in form , so I can not use Me.DocumentoCompra .

For this I am editing the document that I want to clone, invoking the function ClonaObjecto . I hit Tipodoc and update but is giving an error:

  

0: Unspecified error

What is the correct way to do this?

Dim objCopia As GcpBEDocumentoCompra
Set objCopia = New GcpBEDocumentoCompra

Dim objOrig As GcpBEDocumentoCompra
Set objOrig = Aplicacao.BSO.Comercial.Compras.Edita("000", "FPD", "2018", "8")


'Clona o objeto de origem
Set objCopia = PSO.FuncoesGlobais.ClonaObjecto(objOrig)                   
objCopia.TipoDoc = "FD"

BSO.Comercial.Compras.Actualiza objCopia
BSO.Comercial.Compras.Actualiza objOrig
    
asked by anonymous 16.11.2018 / 18:56

1 answer

3

The problem may almost certainly be due to the lack of assignment of header and row IDs, plus you have to indicate that the EmModoEdicao property has False value, otherwise the engine will understand that the document is not new and will try to update.

The code below should answer your question:

Dim objCopia As GcpBEDocumentoCompra
Dim objOrig As GcpBEDocumentoCompra

Set objOrig = Aplicacao.BSO.Comercial.Compras.Edita("000", "FPD", "2018", "8")

'Clona o objeto de origem
Set objCopia = PSO.FuncoesGlobais.ClonaObjecto(objOrig)

With objCopia
    .TipoDoc = "FD"
    .EmModoEdicao = False
    .Id = PSO.FuncoesGlobais.CriaGuid(True)
End With

For Each objLinha In objCopia.Linhas
    objLinha.IDLinha = PSO.FuncoesGlobais.CriaGuid(True)
Next

BSO.Comercial.Compras.Actualiza objCopia

Set objCopia = Nothing
Set objOrig = Nothing

We basically cloned the object and then changed all the IDs, indicated that it was a new document and we recorded it.

    
17.11.2018 / 11:51