Update Records in Xero
Table of Contents
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.
- Bank Accounts
<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.
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,
- Select the Form from your Dashboard page.
- Click on Settings - On Add - Actions on Success.
- Add the script to the editor area.
- 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();
// Update the record
updateresponse = xero.update("Xero", "contacts", id, param);
- Upon submitting the form, the Name of the respective contact in Xero Contacts module gets updated to "John Taylor Smith".
- 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)
The response returned by Xero will be in the format given below:
"ProviderName":"Zoho Creator Local",
"Name":"John Taylor Smith",
If the execution fails due to incorrect parameter value,the response will be in the following format:
"Message":"A validation exception occurred",
"Message":"The contact name John Smith is already assigned to another contact. The contact name must be unique across all active contacts."
To add the script using the drag-n-drop functionality in Script Builder,
- Select the Form from your Dashboard page
- Click on Settings - On Add - Actions on Success
- Click on Script Builder from the top-right corner of the page.
- Drag and drop the call function in the editor box.
- Select Integration tasks.
- Select Service as Xero.
- Select Function as Update Record.
- 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.
- Select the required Module name in Xero.
- 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.
- Specify the response variable that will hold the response returned by Xero.
- 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.
- The key-value pairs displayed will differ based on the module selected.