Custom Function to update customer record when creating an invoice

Custom Function to update customer record when creating an invoice

Hi, I'm new to Zoho Invoices.

I have created a custom field in the Customers table called 'Royalty'. Each time an invoice is created for that customer I want the total invoice value to be added to the Royalty field. 

The Royalty field will be a running total which I can reset (set to 0) at anytime.

Can I do this with a custom function - if so could you please provide a code example ?   I've looked in the documentation but don't see anything like this.

Thanks

Dale