Update Records in Xero

Table of Contents

Overview

The xero.update() task is used to update existing records in any of the supported modules in your Xero account, directly from your Zoho Creator application. For example, you can update Contacts, update Items with details like account price and unit price, update your bank account details, update invoices for sales, bills etc. To connect Zoho Creator with Xero, add a new connection from the Setup - Connections page.

Supported Modules

  • Contacts
  • Items
  • Bank Accounts
  • Invoices

Syntax

updateresponse = xero.update("xeroConnectionName", "xeroModuleName", "xeroRecordID", params);

where,
<updateresponse> is the map variable returned as response. It contains the details of the newly created record.
<xeroConnectionName> refers to the connection name used to connect Zoho Creator with Xero. Create a new connection from the Setup - Connections page.
<xeroModuleName> refers to the module name in Xero where the record is created.
<xeroRecordID> refers to the ID of the record in Xero which needs to be updated.
<params> is the map variable that holds the key,value pairs. The map key is the label name in the format as specified in Xero API Guide. The map value is the field value as submitted from a Zoho Creator application.

Example - To update a record

A sample script to update contact details in Xero Contacts module is given below. Lets say we have a Zoho Creator form with fields related to Xero Contacts module. Add the following script to the required Form Actions block of this form to update a record in the Contacts module. For example, to update the Name of the contact,

  1. Select the Form from your Dashboard page.
  2. Click on Settings - On Add - Actions on Success.
  3. Add the script to the editor area.
  4. Click on Save Script to save the script definition.

    //Fetch record that you want to update using your preferred parameter. In this case, we have used the FirstName field from the Creator Form.
    getresponse = xero.getRecords("Xero", "contacts", "FirstName=\"John\"");

    //Convert the fetched data into string list and fetch its ID
    contactList = getresponse.get("Contacts").toJSONList();
    for each resMaptemp in contactList
    {
    resMap = resMaptemp.toMap();
    id = resMap.get("ContactID");

    //Declare Map Variable to hold the updated contact details
    a = map();
    a.put("Name", "John Taylor Smith");
    param = map();
    param.put("Contact", a);

    // Update the record
    updateresponse = xero.update("Xero", "contacts", id, param);
    }

  5. Upon submitting the form, the Name of the respective contact in Xero Contacts module gets updated to "John Taylor Smith".

Note

  • You can add the script directly to the editor area by selecting Free-flow scripting link displayed on the top-right corner of the script builder ( or ) use the drag-and-drop functionality in Script Builder.
  • In the above example, we have specified the param values directly within quotes. To fetch the param values from a Zoho Creator form, specify the field deluge name used in the form. For example, if First_Name is the Field Deluge name, the key value pair should be specified in the following format: ("FirstName", First_Name)

Response Format

The response returned by Xero will be in the format given below:

{
"Status":"OK",
"ProviderName":"Zoho Creator Local",
"Contacts":"[{"Phones":[
{
"PhoneCountryCode":"",
"PhoneAreaCode":"",
"PhoneNumber":"",
"PhoneType":"FAX"
},
],
"Addresses":[
{
"PostalCode":"",
"Region":"",
"AddressType":"STREET",
"Country":"",
"City":""
}
],
"UpdatedDateUTC":"/Date(1415741574050+1300)/",
"ContactStatus":"ACTIVE",
"IsCustomer":false,
"ContactPersons":[

],
"LastName":"Smith",
"SalesTrackingCategories":[

],
"Name":"John Taylor Smith",
"PurchasesTrackingCategories":[

],
"ContactID":"4f80a131-3943-4dc3-9dd6-032d727ccdad",
"EmailAddress":"",
"FirstName":"John",
"ContactGroups":[

],
"BankAccountDetails":"",
"HasValidationErrors":false,
"IsSupplier":false
}
]","Id":"3117bd0c-3772-4b14-b2fa-6065246c2c3e",
"DateTimeUTC":"/Date(1415788374048)/"
}

If the execution fails due to incorrect parameter value,the response will be in the following format:

{
"Message":"A validation exception occurred",
"Type":"ValidationException",
"Elements":"[{" Phones":[

],
"Addresses":[

],
"Attachments":[

],
"LastName":"Smith",
"ContactPersons":[

],
"Warnings":[

],
"ValidationErrors":[
{
"Message":"The contact name John Smith is already assigned to another contact. The contact name must be unique across all active contacts."
}
],
"SalesTrackingCategories":[

],
"Name":"John Smith",
"PurchasesTrackingCategories":[

],
"ContactID":"00000000-0000-0000-0000-000000000000",
"ContactGroups":[

],
"HasValidationErrors":true
}
]","ErrorNumber":10
}

Using Script Builder

To add the script using the drag-n-drop functionality in Script Builder,

  1. Select the Form from your Dashboard page
  2. Click on Settings - On Add - Actions on Success
  3. Click on Script Builder from the top-right corner of the page.
  4. Drag and drop the call function in the editor box.
  5. Select Integration tasks.
  6. Select Service as Xero.
  7. Select Function as Update Record.
  8. Select the Connection Name to connect with Xero. Click on +Create to create a new connection or create a new connection from the Setup - Connections page.
  9. Select the required Module name in Xero.
  10. Select the map variable that holds the key-value pairs for the create request (or) click on "New Map" to add key-value pairs for the create request.
  11. Specify the response variable that will hold the response returned by Xero.
  12. Click on Done to insert the call function task.


Upon submission of the form, the record gets updated in the selected module of Xero with the given values. The response variable will contain the response returned by Xero.

Note

  • The key-value pairs displayed will differ based on the module selected.

Share this post : FacebookTwitter