Search code examples
phpquickbooksintuit-partner-platformquickbooks-onlineqbxml

How to set a custom field's value using Keith Palmer's QBO framework?


I'm trying to add a value to a custom field using Keith Palmer's QBO PHP framework. I've added the custom field Test Field in the quickbooks settings and now every invoice has a CustomField property with the following properties:

DefinitionId, Name, Type

Each of the above types are arrays.

However, I can't seem to set the custom field's value.

The following code doesn't seem to work.

// Add a custom field to the invoice (YOU NEED TO DEFINE THIS IN THE QBO PREFERENCES FIRST!!!)
$CustomField = new QuickBooks_IPP_Object_CustomField();
$CustomField->setName('Test Field');
$CustomField->setType('StringType');
$CustomField->setStringValue('Test value here');
$Invoice->addCustomField($CustomField);

UPDATE:

What worked for me was the following:

    $custom_field = new QuickBooks_IPP_Object_CustomField();
    $custom_field->setDefinitionId('1');
    $custom_field->setName('Status');
    $custom_field->setType('StringType');
    $custom_field->setStringValue('Test value here');
    $invoice->setCustomField($custom_field);

And in my quickbooks account, I had manually set the first custom field to 'Status'.


Solution

  • At the data service level, you can retrieve or update QuickBooks Online custom fields that have already been configured at the product level. You can't create them.Note:Remember to use DefinitionId(unique id for custom fields for update)

    https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/custom_fields