From V6 onwards, you can fetch the related records of a deleted record using the Get Related Records of a Deleted Record API. It is important to note that this API allows the retrieval of related records associated via lookups. For more detailed information, please refer to the API help documentation.
n = 1000; //Upto 100,000 records can be fetched. In our case, we are fetching 100 records in a single call, so the code iterates 1,000 times. counter = leftpad("1",n).replaceAll(" ","1,").toList(); i = 1; for each el in counter { reqUrl = "https://www.zohoapis.com/crm/v6/Purchase_Orders/deleted/" + poid.toString() + "/Stock_Records1?fields=Stock_Status&page=" + i.toString() + "&per_page=100"; response = invokeurl [ url :reqUrl type :GET connection:"zohocrm" ]; lis = List(); i = i + 1; for each stockList in response.get("data") { idData = stockList.get("id"); mp = Map(); mp.put("Stock_Status","Available"); mp.put("id",idData); lis.add(mp); } updRes = zoho.crm.bulkUpdate("Stock_Records",lis); if(!response.get("info").get("more_records")) { break; } } |
The script initiates an API call to retrieve the unique IDs of deleted records in the Purchase Orders module. The URL includes parameters for the page number and records per page, and the response is stored in the response variable.
The script iteratively fetches stock records associated with the deleted purchase order, updating the Stock Status for each record to Available in bulk operations. The loop continues until the more_records value in the response is false, represents the completion of record retrieval. Note that you can fetch 100000 records using pagination.
The Workflow updates the value of the Stock Status field in the related records when a record in the Purchase Orders module is deleted.
The below GIF shows how to associate the function with a newly created workflow.
Happy Coding!
Previous Kaizen Post : Kaizen #118 - Mass Delete Records Across Modules
Writer is a powerful online word processor, designed for collaborative work.