Hi,
I want to develop a Deluge script to track resources we rent to customers.
1) when an invoice is issued
- take each line of the invoice
- find the product of this line
- link this product to the Account (invoice's Account) with a custom search field
-> all this is working well (see below)
2) but when a product line is deleted from the invoice (or if the invoice itself is deleted), the Product's "Account serach field" keeps the relation with the account.
Is there a way to keep the integrity of the database in this situation? I the case the Invoice is deleted, I'd go with a "item deleted" trigger to loop through the Invoice lines and do the job. But how do that if only one line is deleted?
I tried to use a direct relation between Accounts and Products (would have been fine) but the "delete" link (on the Account's Products Associated List) actually delete the Product (!?!?) instead of deleting the link. Don't really understant yet in which situation this functionnality is useful...
Any thoughts?
f_maj_facture (int accountID,
string accountName)
//MODULE COMPTE / CHAMPS FACTURES - TOTAL / inscrire le total des factures
//Identifier les factures liées au compte "string accountID"
factures = zoho.crm.getRelatedRecords("Invoices",("Accounts"),(input.accountID).toString(),1,200);
//Mettre les variables à 0
total_factures=0;
//Trouver les infos dans chaque facture liée au compte
for each facture in factures
{
lignes_facture=facture.get("product").toJSONList();
//Pour chaque ligne de la facture
for each ligne_facture in lignes_facture
{
ligne_facture_map=ligne_facture.toMap();
productID=ligne_facture_map.get("Product Id");
produit = zoho.crm.getRecordById("Products",productID.toLong());
ThisMap=map();
ThisMap.put("Compte propriétaire","Linovati");
Reponse = zoho.crm.updateRecord("Products",productID.toString(),ThisMap);
total_factures=(total_factures + (ligne_facture_map.get("Net Total")).toLong());
}
ThisMap=map();
ThisMap.put("Factures - total",total_factures);
Reponse = zoho.crm.updateRecord(("Accounts"),(input.accountID).toString(),ThisMap);
}