Deluge Script In CRM To Deal With More Than 200 Records
Hi,
I have a Deluge script, which works perfectly. We have a custom field in the Campaigns module called Total_Raised which looks at the Donation_Amount field in the custom module, Donations. The idea is to sum up the total of all donation amounts.
However, it stops at 200 records, the Zoho default cut-off, as I understand it. Is there any way of being able to search through more than 200 records, possibly up to 2000? My existing working code is:
- void automation.UpdateDonationTotal(Int campaignId)
- {
- if(campaignId != null)
- {
- // Fetch related donations for the given Campaign ID
- donations = zoho.crm.getRelatedRecords("Donations", "Campaigns", campaignId, 1, 200);
- // Initialize the total amount
- totalRaised = 0.0;
- // Iterate over each donation and sum the Donation Amount
- for each donation in donations
- {
- if(donation.get("Donation_Amount") != null)
- {
- totalRaised = totalRaised + donation.get("Donation_Amount");
- }
- }
- // Fetch the current Campaign record to compare Total_Raised
- campaignRecord = zoho.crm.getRecordById("Campaigns", campaignId);
- existingTotal = campaignRecord.get("Total_Raised");
- // Debugging log
- info "Campaign ID: " + campaignId;
- info "Total Raised (calculated): " + totalRaised;
- info "Existing Total Raised: " + existingTotal;
- // Update only if the calculated value differs from the existing value
- if(existingTotal != totalRaised)
- {
- // Prepare data for updating the Campaign's Total Raised field
- updateMap = Map();
- updateMap.put("Total_Raised", totalRaised);
- // Update the Campaign record
- response = zoho.crm.updateRecord("Campaigns", campaignId, updateMap);
- if(response.get("code") == "SUCCESS")
- {
- info "Successfully updated Total Raised for Campaign ID: " + campaignId;
- }
- else
- {
- info "Failed to update Total Raised for Campaign ID: " + campaignId + ". Response: " + response;
- }
- }
- else
- {
- info "No update needed. Total Raised is already correct.";
- }
- }
- else
- {
- info "Invalid Campaign ID: " + campaignId;
- }
- }
Is there any way we can search more than 200 records and make the calculation?