Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error to copy content of XML file to Cursor
Message
From
08/02/2022 04:30:20
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Error to copy content of XML file to Cursor
Miscellaneous
Thread ID:
01683464
Message ID:
01683464
Views:
66
Hello comunity,

I try to passed the content of my XML file to cursor, but i have always this error that curiously appear only if i try to import 1 day from my XML fiel to my cursor crstmp ??

My code:
Local loJson
Local lcJsonStr
Local lnSuccess
Local loartigos
Local lnNumArtigos
Local i
Local loArtObj
Local lnDos
Local lnContador
Local lnArm
Local lnCl
Local lnEstabt

lnCl = 443
lnEstab = 7 &&Loja ECI Gaia
lnDos = 323 &&Sales Report

lnCl_l = 50002 &&80001
lnEstab_l = 0 &&0 &&Loja ECI Gaia
lnDos_l = 323  &&340 &&Sales Report

lnContador = 0
lnArm = 91 &&113  &&Loja ECI Gaia

*!* Qual a data da ultima alteração

Create Cursor xVars ( no N(5), tipo c(1), Nome c(40), Pict c(100), lOrdem N(10), tbVal m, nValor N(18,5), cValor c(250),mValor m, lValor l, dValor d )

Select xVars
Append Blank
Replace xVars.no With 1
Replace xVars.tipo With "D"
Replace xVars.Nome With "Desde a Data"
Replace xVars.Pict With "##.##.####"
Replace xVars.lOrdem With 1
Replace xVars.dValor With (Date() - 1)

m.mCaption = "Artigos alterados desde a datas...?"
m.escolheu=.F.
docomando("do form usqlvar with 'xvars',m.mCaption")

If m.escolheu=.T.

	Select xVars
	Go Top
	Locate For xVars.no=1
	pd_data=xVars.dValor
	If datavazia(xVars.dValor)
		pd_data = Date()-1
	Endif

	If pd_data <= Ctod('31.01.2020')
		msg("Não pode importar entradas com data inferior a 31-01-2020")
	Else

		xmlHttp = Createobject("MSXML2.ServerXMLHTTP")
		xmlHttp.Open("GET", "https://castelbel.bsoftware.pt/public/castelbelapi/dossiers_store?ndos=" + astr(lnDos) +"&no=" + astr(lnCl) +"&estab=" + astr(lnEstab) +"&dataobra=" + Dtoc(pd_data) + "&format=xml" , Null, "castelbel", "mypassword")
		xmlHttp.setRequestHeader("Content-Type", "application/php")
		xmlHttp.Send("")
		result = xmlHttp.responseText
		result = Strtran(result, 'encoding="utf-8"', 'encoding="iso-8859-1"')
		result = Strtran(result, '>.</', '></')
		result = Strtran(result, "'", "`")

		Strtofile(result, 'dossiers.xml')
		Try
			Xmltocursor('dossiers.xml','dossiers',512)
			*BROW
			*return

			lnNumDossiers = Reccount("dossiers")
		Catch To oError When .T.
			lnNumDossiers=0
			msg("Não existem nada a importar!")

		Endtry

		If lnNumDossiers > 0

			* Criar cursor para conteudo do ficheiro
			Create Cursor crstmp (bostamp c(25), bistamp c(25), dataobra d ,ref c(18), qtt N(19,6), lote c(40), obrano c(10), lOrdem N(10), Design c(60))


			Select dossiers
			Scan

				If astr(dossiers.u_glnentr) = '5600000025963' And VAL(dossiers.qtt) <> 0
					Select crstmp
					Append Blank
					Replace crstmp.dataobra With Ctod(Substr(dossiers.dataobra,9,2) +'.'+Substr(dossiers.dataobra,6,2) +'.'+Substr(dossiers.dataobra,1,4))
					Replace crstmp.bostamp With Alltrim(dossiers.bostamp)
					Replace crstmp.bistamp With Alltrim(dossiers.bistamp)
					Replace crstmp.ref With Alltrim(dossiers.ref)
					Replace crstmp.qtt With VAL(dossiers.qtt)   && Error happen here 
					Replace crstmp.lote With Alltrim(dossiers.lote)
					Replace crstmp.obrano With astr(dossiers.obrano)
					Replace crstmp.Design With Alltrim(dossiers.Design)
					Replace crstmp.lOrdem With dossiers.lOrdem
				Endif
				select dossiers
			Endscan


			* Criar dossier por bostamp distinto.

			Select crstmp

			Select bostamp, obrano, dataobra From crstmp Group By bostamp Order By dataobra Into Cursor crsbo Readwrite &&HERE
			Select crsbo

			If Reccount("crsbo") > 0

				Scan
					Wait Window "a processar encomenda ..." Timeout 1

					*!* verificar se o dossier já existe

					If u_sqlexec ("select bostamp from bo (nolock) where bo.u_oristamp = '" + Alltrim(crsbo.bostamp) + "'","wst")

						Select wst

						If Reccount ("wst") = 0

							If SBO.adding=.T. Or SBO.editing=.T.
								Mensagem("Existem registos que ainda não estão gravados...","Directa")
								Return .F.
							Endif

							criar_cabecalhos(lnDos_l, lnCl_l , lnEstab_l, crsbo.bostamp)
							SBO.Refresh()


							*!* preenche a 1 linha
							Select BI
							Replace BI.Design With 'Documento importado via API e criado por : ' + m.m_chinis + ' | ' + Dtoc(Date())

							Select crstmp
							Go Top
							ln_lordem = 0

							Scan For crstmp.bostamp = crsbo.bostamp
								Select BI
								Go Bottom
								Do boine2in

								Replace BI.dataobra With crstmp.dataobra
								Replace BI.ref 		With crstmp.ref,;
									BI.qtt 		With crstmp.qtt ,;
									BI.Design With crstmp.Design
								*BI.lOrdem With crstmp.lOrdem

								Do BOACTREF

								Replace BI.armazem		With lnArm,;
									BI.lote		With crstmp.lote

								Do u_bottdeb With 'bi'
								Do BOTOTS With .T.
							Endscan

							Do BOTOTS With .T.
							SBO.localrefrescar()
							SBO.Refresh()

							GE_USERBRULE = .F.
							BO_APRINT = .F.

							Wait Window "a gravar..." Timeout 1
							SBO.Bok1.Okbuttomdef1.Click

							GE_EVENTOS = .T.
							GE_UDEFS = .T.

						Endif

					Endif
				Endscan

			Endif
		Endif
		Mensagem("Foi concluída processo de importação.","Directa")
	Endif
Endif

FECHA([dossiers])
FECHA([crstmp])

Procedure criar_cabecalhos(pnDos, pnCl, pnEstab, pcOristamp)
	SBO.newndos(pnDos)
	SBO.dointroduzir()
	SBO.Refresh()



	u_sqlexec("select clstamp, no, estab, nome from cl where cl.no = "+astr(pnCl)+" and cl.estab = "+astr(pnEstab),"crsCL")
	Select crsCL
	doread("CL","SCL")
	navega("CL",crsCL.clstamp)
	Do While Type("SCL") <> 'O'
		aguarde("Aguarde por Favor...")
	Enddo
	If Type("SCL")="O"
		scl.Visible=.F.
	Endif

	Select BO
	Replace BO.no 		With crsCL.no,;
		BO.estab 		With crsCL.estab,;
		BO.Nome			With crsCL.Nome,;
		BO.u_oristamp   With pcOristamp,;
		BO.obranome     With crsbo.obrano,;
		BO.dataobra     With crsbo.dataobra  &&HERE

	Select BO2
	Replace BO2.exportado With .T.

	boclact("MAIN",.T.)
	SBO.Refresh()
Endproc

Procedure criar_linhas()
	Select BI
	Go Top

	If crsCL.no = 443 And crsCL.estab = 7

		If N = 1
			Replace BI.Design	With Alltrim(crsbi.nmdos) + ' nº ' + astr(crsbo.obrano) + ' de ' + Dtoc(crsbo.dataobra)
		Endif

		Do boine2in
		Replace BI.ref 		With crsbi.ref
		Do BOACTREF With 'NORMAL',.T.,'OKPRECOS','bi'
		Replace BI.Design	With crsbi.Design,;
			BI.qtt		With crsbi.qtt, ;
			BI.edebito	With crsbi.edebito,;
			BI.desconto	With crsbi.desconto,;
			BI.desc2	With crsbi.desc2,;
			BI.desc3	With crsbi.desc3,;
			BI.desc4	With crsbi.desc4,;
			BI.desc5	With crsbi.desc5,;
			BI.armazem	With crsbi.armazem,;
			BI.lOrdem	With crsbi.lOrdem,;
			BI.obistamp	With crsbi.bistamp,;
			BI.oobistamp	With crsbi.bistamp,;
			BI.lobs2	With crsbi.lobs2,;
			BI.desc6	With crsbi.desc6
		Do u_bottdeb With 'bi'
		Do BOTOTS With .T.
	Endif
Endproc
error that appear:
Código: 11
Linha: 94
Mensagem 1: Function argument value, type, or count is invalid.
Mensagem 2: create cursor dossiers from array _XMLArray_B8468283_C239_4DA8_B4B2_49FAD15EB656_


I think the problem is because about the conversion from Character to VAL() : Replace crstmp.qtt With VAL(dossiers.qtt) !?, maybe?

Could someone help me, please !

Many thanks,
Luis
Next
Reply
Map
View

Click here to load this message in the networking platform