Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Insert the Bill's Date as the Bill Number, since we usually don't care what the Bill Number is but Zoho Books needs it, yet when a bill is created via recurring profile, it doesn't generate one.
*
* If it's already set, it won't be modified.
* Example result if Bill Date is December 10, 2019 (DueDate is disregarded): "Auto: 2019-12-10"
*
* Created 2019-12-10. Confirmed still working 2020-04-30.
* Will NOT work on VOID bills.
* WARNING: The user that CREATES the custom button is the only user that can EDIT the custom button.
*
* [This snippet]{@link https://gist.github.com/cliffordp/9f536f008e247e98e91f0ac36a515610}
* [Preferences: about custom buttons]{@link https://www.zoho.com/us/books/help/settings/preferences.html#buttons}
* [Preferences screenshot with this custom button added]{@link https://share.getcloudapp.com/2NuXwN1J}
* [About Deluge]{@link https://www.zoho.com/deluge/help/}
* [Learn Deluge playground]{@link https://creator.zoho.com/learndeluge/}
* [Deluge: Update record]{@link https://www.zoho.com/deluge/help/books/update-record.html}
* [Deluge: Update records in Zoho Books]{@link https://www.zoho.com/creator/help/script/update-records-in-zoho-books.html}
*/
prefix = 'Auto: ';
resultMap = Map();
origBillNumber = bill.get( 'bill_number' );
// Bail if already set
if ( ! origBillNumber.isBlank() ) {
resultMap.put( "message", "N/A: Bill Number " + origBillNumber + " already exists. Not modified. Don't click this button again for this Bill." );
resultMap.put( "code", 1 );
// 0 - Success ; Other than 0 will consider as failure
return resultMap;
}
billDate = bill.get( 'date' );
// Set bill date to Now in company's preferred date format
if ( billDate.isBlank() ) {
billDate = now.toString( organization.get( 'date_format' ) );
}
response = zoho.books.updateRecord( "Bills", organization.get( 'organization_id' ), bill.get( 'bill_id' ), { 'bill_number': prefix + billDate } );
responseCode = response.get( 'code' );
if ( '0' == responseCode ) {
resultMap.put( "message", "Success: Bill Number inserted." );
}
resultMap.put( "code", responseCode );
// 0 - Success ; Other than 0 will consider as failure
return resultMap;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.