The example shows you how to:


Prerequisites


Set up

  1. Open TestObject.js and note how AbstractTestObject extends Intacct/SDK/Functions/AbstractFunction.

    AbstractFunction is a helper class provided mainly to generate random control IDs. AbstractFunction implements Intacct/SDK/Functions/IFunction, and any class whose instances will be executed by a client must implement IFunction. If using executeBatch, the parameter must be an IFunction[] array.

  2. In TestObject.js note how TestObjectCreate extends AbstractTestObject.

    The IFunction interface requires that the class implement the writeXml(xml) function. This implementation is where you provide the XML that will be processed at the gateway endpoint.

  3. Back in the AbstractTestObject class, replace test_object with the integration name for your custom object.

    this.integrationName = "test_object";
    

Run the example

  1. Run the custom-object-function.js file:

    node custom-object-function.js
    
  2. Observe the terminal output, which should look similar to this:

    Created record ID 10153
    

    Note the record ID, which will be used to delete the object later.

  3. Open the generated logs/intacct.log file in a text editor and review the entries.

    The file provides info and debug entries. The SDK provides a debug entry for each HTTP request/response (with the Sage Intacct endpoint).

    Note that the log file was created by the logger set in the client config.


Extra credit

Get the record by ID

  1. Update custom-object-function.js to execute a Read function using the record ID returned by TestObjectCreate as the key. For example:

    const read = new IA.Functions.Common.Read();
    read.objectName = "test_object";
    read.keys = [
        10174,
    ];
    
    const readResponse = await client.execute(read);
    
    const readResult = readResponse.getResult();
    const recordNo = parseInt(readResult.data[0]["id"]);
    console.log("Read record ID " + recordNo.toString());
    

Delete the record

  1. Create a TestObjectDelete class in TestObject.js and execute an instance of it that uses the same record ID returned in the TestObjectCreate result.

    If you need help, see .

    class TestObjectDelete extends AbstractTestObject {
        constructor(recordId) {
            super();
            this.id = recordId;
        }
       
        writeXml(xml) {
            xml.writeStartElement("function");
            xml.writeAttribute("controlid", this.controlId, true);
            xml.writeStartElement("delete");
       
            xml.writeElement("object", this.integrationName, true);
            xml.writeElement("keys", this.id, true);
       
            xml.writeEndElement(); // delete
            xml.writeEndElement(); // function
        }
    }
    exports.TestObjectDelete = TestObjectDelete;
    

What’s next?

For more complex examples, you can use the functions in the SDK as models. For example, AbstractBill extends AbstractFunction, then BillCreate and BillDelete extend AbstractBill and write the XML for creating or deleting bills.

Provide feedback