DominicProgrammer
IS-IT--Management
Hi Experts.
I have an issue here trying to create a json like txt file so i can use in in API link but i cant get the products coming in records [there are only 2 records in that temp table] why does the records duplicate in the ItemDetails object ? Kindly assist me. Thanks in advance:
I have an issue here trying to create a json like txt file so i can use in in API link but i cant get the products coming in records [there are only 2 records in that temp table] why does the records duplicate in the ItemDetails object ? Kindly assist me. Thanks in advance:
Code:
Close All
lcCRLF = Chr(13)+Chr(10)
local krec,i
Use temp In 0
Select temp
Go Top
orec=1
i=1
SCAN
krec=Recno()
Scatter Memvar
kstockcode=stockcode
Strtofile(['{"CallBackUrl":"[URL unfurl="true"]http://192.168.0.5:8128/kekaapi/invoices",[/URL]]+lcCRLF, [c:\json.txt], .F.)
Strtofile(["InvoiceNumber":,] +'"'+Alltrim(m.docno)+'"'+','+ lcCRLF, [c:\json.txt], .T.)
Strtofile(["TotalInvoiceAmount":,] +'"'+Alltrim(Str(m.amount))+'"'+','+ lcCRLF, [c:\json.txt], .T.)
Strtofile(["TotalDiscount":,] +'"'+Alltrim(Str(m.discamt))+'"'+','+ lcCRLF, [c:\json.txt], .T.)
Strtofile(["PINOfBuyer":,] +'P001244574Q'+','+ lcCRLF, [c:\json.txt], .T.)
Strtofile(["HeaderFields":] +'{'+','+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ "Header1": "",] +''+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ "Header2": "",] +''+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ "Header3": "",] +''+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ "Header4": "",] +''+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ "Header5": "",] +''+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ },] +''+ lcCRLF, [c:\json.txt], .T.)
**----------------Item details
Strtofile(["ItemDetails":] +'[{ "HSCode"'+":"+','+ lcCRLF, [c:\json.txt], .T.)
for i=1 to RECCOUNT()
Strtofile([ "ItemCode":,] +'"'+Alltrim(m.stockcode)+'"'+','+ lcCRLF, [c:\json.txt], .t.)
Strtofile([ "Description":,] +'"'+Alltrim(m.desc)+'"'+','+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ "UnitInclPrice":,] +'"'+Alltrim(Str(m.unitprice))+'"'+','+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ "UnitDiscount":,] +'"'+Alltrim(Str(m.discamt))+'"'+','+ lcCRLF, [c:\json.txt], .T.)
Strtofile([ },] +''+ lcCRLF, [c:\json.txt], .T.)
krec=krec+1
NEXT
Strtofile([} ]+''+ lcCRLF, [c:\json.txt], .T.)
Select temp
Endscan
Modify File c:\json.txt