Sentencies SQL per desmarcar una factura electrònica de SAP Business One i permetre que es pugui tornar a generar:

declare @docentry int = 16378 
update OINV set EDocExpFrm=NULL,EDocGenTyp='L' where DocEntry=@docentry 
update ECM2 set ActStatus='W',ActEnv=NULL,Submits=0,GenType='L' Where SrcObjAbs=@docentry and SrcObjType=13 and Code='E' 
--delete ECM2 where AbsEntry=1 
--delete ECM3 where AbsEntry=1

Notes:

  • Amb els UPDATES ja n’hi ha prou
  • (OPCIONAL) Si volem netejar el monitor, podem fer els DELETE

Actualització amb número de document

declare @docentry int
declare @docnum int = 20510057
select @docentry=DocEntry from OINV where DocNum=@docnum
update OINV set EDocExpFrm=NULL,EDocGenTyp='L' where DocEntry=@docentry
update ECM2 set ActStatus='W',ActEnv=NULL,Submits=0,GenType='L' Where SrcObjAbs=@docentry and SrcObjType=13 and Code='E'

Format de factura que està funcionant a TEYDER https://www.dropbox.com/s/16o8irbvmyzsvq9/einvoice_intrx_ok.spp?dl=1

Quan la factura sembla que està correctament configurada però no surt al monitor: (compta que el AbsEntry es el AutoKey del objecte 1730000000 de ONNM)

INSERT INTO ECM2 
(AbsEntry,Code,ActType,ActStatus,IsRemoved,ObjectID,SrcObjType,SrcObjAbs,Cancel,GenType,TestMode,PeriodNum,Year,UserSign,CreateDate,CreateTS,UpdateDate,UpdateTS,GUID,CancStatus) 
VALUES 
(44011,'E','D','W','N','FA '+CONVERT(nvarchar,25196), 13,25196,'N','L','N',-1,-1,8,GETDATE(),100000,GETDATE(),100000,REPLACE(NEWID(), '-', ''),'T')

Versió per HANA

DO
BEGIN
  DECLARE docEntry int;
  DECLARE docNum int = 229004;
  
  select "DocEntry" into docEntry from OINV where "DocNum"=docNum;
  update OINV set "EDocExpFrm"=NULL,"EDocGenTyp"='L' where "DocEntry"=docEntry;
  update ECM2 set "ActStatus"='W',"ActEnv"=NULL,"Submits"=0,"GenType"='L' Where "SrcObjAbs"=docEntry and "SrcObjType"=13 and "Code"='E';
  
END;