Scheduled task to update Invoice Payment Status in Creator

Scheduled task to update Invoice Payment Status in Creator

Hi Team

I have ZC and ZI. ZC currently creates invoices in ZI and keeps a lot of the created invoice ID. I need to set up a scheduled task that runs through records where payment status = "Not Paid" and check each record in Invoice for any change in payment status. If paid it should update the Payment Status to Paid. I can do this for an individual record using GetInvoiceInfo() but how do I nest that inside a For Each function so that  it runs through each record and checks/updates?

I currently have a scheduled task set up that runs daily against a filtered record list. Here is the code

coEmail = Account[ID>0].Company_Email;
coName = Account[ID>0].Company_Name;
for each r in Service_Order[Payment_Status=="Not Paid"]
{
resp = zoho.invoice.getinvoiceinfo(r.Invoice_ID,coName);
if((resp.get("Total")).toDecimal()  >  (resp.get("Balance")).toDecimal())
{
r.Payment_Status="Paid";
else
{
r.Payment_Status="Not Paid";
}
}
}

This returns an error at line 3. Also, is this the correct way to do this?

Thanks a lot
Regards
Jason