intacct / intacct-sdk-js

Official repository of the Sage Intacct SDK for JavaScript in Node.js
https://developer.intacct.com/tools/sdk-node-js/
Apache License 2.0
22 stars 31 forks source link

InvoiceCreate - lines property #121

Closed kpiercy closed 1 year ago

kpiercy commented 1 year ago

When attempting to use InvoiceCreate, I am unsure how to implement the structure of the call regarding the lines property. Apologies, but first time using the Intacct SDK and have not received any help from web searches on how to handle. Documentation would seem to suggest that the following should work:

create.lines = { glAccountNumber: '40100', totalDue: '1111' }

Below is the function I am using with commented out attempts for things I have tried. Kind of at a loss on what the code should look like here for the lines property.

`async create() {

    const bootstrap = require('../bootstrap')
    const IA = require('@intacct/intacct-sdk')
    let logger = bootstrap.logger()

    try {
        const client = bootstrap.client(logger)

        logger.info('Executing CreateInvoice to API')

        let create = new IA.Functions.AccountsReceivable.InvoiceCreate()
        create.customerId = "10011"
        // create.dateCreated.year = "2023"
        // create.dateCreated.month = "07"
        // create.dateCreated.day = "05"

        // create.invoiceitems = {
        //     lineitem: [
        //         invItems
        //     ]
        // }

        // create.invoiceitems = {
        //     lineitem: invItems
        // }

        // create.invoiceitems = {
        //     invoiceitems: {
        //         lineitem:
        //             invItems
        //     }
        // }

        // create.invoiceitems = {
        //     invoiceitems: {
        //         lineitem: [
        //             invItems
        //         ]
        //     }
        // }

        // create.invoiceitems.lineitem = [invItems] //TypeError

        // create.invoiceitems.lineitem = [{
        //     glaccountno: "40100",
        //     amount: "1111"
        // }] //TypeError
        // create.invoiceitems = {
        //     lineitem: [
        //         {
        //             glaccountno: "40100",
        //             amount: "1111"
        //         }
        //     ]
        // } //TypeError

        // create.lines = [
        //     {
        //         glAccountNumber: "40100",
        //         totalDue: 1111
        //     }
        // ] //TypeError

        // create.lines = {
        //     invoiceitems: [
        //         {
        //             glAccountNumber: '40100',
        //             totalDue: 1111,
        //         },
        //     ],
        // } //XL03000003 XML Parse schema error: Error 1871

        // create.lines = {
        //     glAccountNumber: '40100',
        //     totalDue: '1111',
        // } //XL03000003 XML Parse schema error: Error 1871

        // create.lines = {
        //     invoiceItems: [
        //         {
        //             lineItem: {
        //                 glAccountNumber: '40100',
        //                 totalDue: '1111',
        //             },
        //         },
        //     ],
        // } //XL03000003 XML Parse schema error: Error 1871

        const createResponse = await client.execute(create)
        const createResult = createResponse.getResult()

        const invoiceId = createResult.data[0]['INVOICEID']

        console.log('Created new Invoice with InvoiceID of ' + invoiceId)
    } catch (ex) {
        if (ex instanceof IA.Exceptions.ResponseException) {
            logger.error('An Intacct response exception was thrown', {
                Class: ex.constructor.name,
                Message: ex.message,
                'API Errors': ex.errors,
            })
            console.log('Failed! ' + ex.message)
        } else {
            logger.error('An exception was thrown', {
                Class: ex.constructor.name,
                Message: ex.message,
            })
            console.log(ex.name)
        }
    }
}`
kpiercy commented 1 year ago

Found the solution. Was using the xml schema documentation as a guide, because the error it throws for this references the xml schema, but needed to use another function call to InvoiceLineCreate.