Writeback basics

If a writeback function throws an “unknown function” error in your Python script, this could be because you are on an old version of the connector. In that case do a “Full Resync” under Connections, so that the newest version of the connector is loaded and used in your writeback scripts. “Full resync” will update the connector used in your account to the latest version.

Write updates to a SaaS connection: add, update, delete records

Here’s an example using Odoo (ERP):

Odoo = pq.connect("Odoo") # use your name of the connection

result = Odoo.update("product", id = 1, name = "New product name")
st.text("Result from writeback: %s" % result)

Odoo.add("product", name="My product", price=100.05) 
Odoo.update("invoice", id=123, payment_state = "in_payment", note = "...")
Odoo.delete("product", id=456)

pq.refresh_connection(connection_name = "Odoo") # see below

Refresh data in Peliqan after writeback

After running a writeback script, you typically want to refresh the data in Peliqan to see the updated data from the source, and potentially verify if the writeback was successful.


pq.refresh_connection(connection_name = "Odoo", is_async = False)
pq.refresh_connection(connection_id = 789)

is_async is an optional parameter:

  • is_async = True (Default): do not wait for refresh to complete
  • is_async = False: wait for refresh to complete

Do not execute multiple refreshes within one script execution. Avoid using refresh in a loop, and call these functions only at the end of your writeback script.

Looping over rows and doing writeback for each row

Example looping over rows of a table in Peliqan for writeback:

dbconn = pq.dbconnect('dw_123')
rows = dbconn.fetch('dw_123', 'schema_name', 'table_name')

for row in rows:
   Odoo.update("product", id = row["id"], name = row["name"])