How to insert Import Json Data into Tally

Discussion in 'Tally & TDL Learning HUB' started by Abisha, Jun 16, 2023.

    
  1. Abisha

    Abisha New Member


    I'm having some difficulty to import Json data into the tally. But I can able to display the contents in a report. My Goal is to insert Json data into the tally as optional voucher. Please Correct my code.

    Code:
    
    [Collection: TSPLJSONFileColl2]
    
    Data Source: FileJSON : "SalesData.json"
    
    JSON Object Path: VOUCHER:1
    Client Only:Yes    
    
    [#Menu:gatewayoftally]
        Button: b2
        [button : b2]
        title: Import JSON
        Key: Alt+I
        Action:Display:Imported Data
       
    [Report:Imported Data]
        Title: $$LocaleString:"Imported Data"
        Form:Imported Data
       
    [Form:Imported Data]
        Part:Imported Data
       
    [Part:Imported Data]
        Scroll:Both
        Common Border:Yes
        Line:Import Report Titles, Import Report Data
        Repeat:Import Report Data:TSPLJSONFileColl2   
    
    [Line:Import Report Titles]
        Fields:ENTRYDATE,VCHNO,VCHHTYPE,PARTY
        Local:Field:ENTRYDATE:Set as:"Date"
        Local:Field:VCHNO:Set as:"Vch No"
        Local:Field:VCHHTYPE:Set as:"Vch Type"
        Local:Field:PARTY:Set as:"Party"
        Local:Field:default:Style:Normal Bold
        Local:Field:default:Align:Left
        Local:Field:default:Border:thinright
        Border:thickbottom
    
    [Line:Import Report Data]
        Space Top:0.5
        Fields:ENTRYDATE,VCHNO,VCHHTYPE,PARTY
        Border:thinbottom
    
    [Field:ENTRYDATE]
        Set as:$DATE
        Width:20
       
    [Field:VCHNO]
        Set as:$VOUCHERNUMBER
        Width:20
       
    [Field:VCHHTYPE]
        Set as:$VOUCHERTYPENAME
        Width:20
       
    [Field:PARTY]
        Set as:$PARTYLEDGERNAME
        Width:20
       
    
    SalesData.json
    Code:
    {
        "VOUCHER": [
          {
            "DATE": "13-01-2023",
            "VOUCHERTYPENAME": "Sales",
            "VOUCHERNUMBER": 40,
            "PARTYLEDGERNAME": "Amar Computer Peripherals",
            "AMOUNT": -1540
          },
          {
            "DATE": "13-01-2023",
            "VOUCHERTYPENAME": "Sales",
            "VOUCHERNUMBER": 41,
            "PARTYLEDGERNAME": "Garçon",
            "AMOUNT": -26000
          },
          {
            "DATE": "13-01-2023",
            "VOUCHERTYPENAME": "Sales",
            "VOUCHERNUMBER": 42,
            "PARTYLEDGERNAME": "ABC PVT",
            "AMOUNT": -5250
          }
        ]
    }
     

    Attached Files:



  2. Sai Vineeth

    Sai Vineeth Active Member


    As I previously mentioned, you need to refer samples and docs as that will give knowledge about TDL.

    See this sample - *\Samples\User Defined Functions\Provisional Vouchers.txt

    I don't know much about TDL as I deal mostly with other languages like c#, python, VBA.

    based on my understanding you are creating instance of voucher object but not committing to database
    to commit you need to call either save target / create target - for better understanding refer sample.
     


  3. Abisha

    Abisha New Member


    Which sample?
     


  4. Sai Vineeth

    Sai Vineeth Active Member


    Tally prime developer has Samples
    located in installation folder
    upload_2023-6-16_18-32-13.png
     
    Last edited: Jun 16, 2023


  5. Devendra_Rawat

    Devendra_Rawat Well-Known Member


    Add following code and in your code on form accept event call the TxoImportVouchers function

    Code:
    [Collection    : TxoVoucherColl]
        Data Source: FileJSON : "SalesData.json"
        JSON Object    : TxoVouchersObjects
        Fetch         : *.*
        Client Only    :Yes
       
    
    [Object    : TxoVouchersObjects]   
        Collection    : Voucher : TxoVoucherObj
       
    [Object    :TxoVoucherObj]
       
           Storage : DATE                : Date
           Storage : VOUCHERTYPENAME    : String
           Storage : VOUCHERNUMBER        : String
           Storage : PARTYLEDGERNAME    : String
           Storage : AMOUNT                : Amount
         
    [Function    : TxoImportVouchers]
       
        Variable    : SVViewName    : String
        Variable    : SVVoucherType    : String
    
       
        10  :   SET             : SVViewName         : $$SysName:AcctgVchView
        15  :   SET                : SVVoucherType    : "Optional"
        20    :    Walk Collection    : TxoVoucherColl
        40    :         NEW OBJECT        : Voucher
        50    :         SET VALUE        : Date                : $DATE
        60     :        SET VALUE        : Is Post Dated        : "No"
        70    :         SET VALUE        : VoucherTypeName    : ##SVVoucherType  
    
        80    :         INSERT COLLECTION OBJECT            : LedgerEntries
        100    :            SET VALUE        : LedgerName        :$ARTYLEDGERNAME
        110    :             SET VALUE        : Is Deemed Positive: "YES"
        120    :             SET VALUE        : Amount            : $$Negative:$AMOUNT
        130    :             SET TARGET        : ..
           
        140    :             INSERT COLLECTION OBJECT            : LedgerEntries
        150    :             SET TARGET        : LedgerEntries
        160    :            SET VALUE        : LedgerName        :"Sales Account" ; - Your Sales Account
        170    :             SET VALUE        : Is Deemed Positive: "NO"
        180    :             SET VALUE        : Amount            : $AMOUNT
        190    :             SET TARGET        : ..
        200 :           SET VALUE       : PersistedView     : ##SVViewName
        210    :             CREATE TARGET
        240    : End Walk
        250    : DISPLAY            : DayBook
        260    : RETURN
    
    ;; End-of-File
    
     


Share This Page