Deluge function not writing lead IDs or updating lead

Deluge function not writing lead IDs or updating lead

Hi all. 
I'm working on my first Deluge function.  The intent is that it gets fired as part of a workflow whenever a certain field is updated for a lead record.  The function needs to write a record to a custom module, and also update the lead record based on certain criteria.

Here is the code.
  1. Void Create_Score_Status_Audit (int LeadID int PersonScore string ScoreStatus )
  2. {
  3. NewScoreStatus=input.ScoreStatus;
  4. OldScoreStatus=input.ScoreStatus;
  5. CurrentPersonScore=input.PersonScore;
  6. CurrentLeadID=input.LeadID.toString();
  7. if((CurrentPersonScore  >  0)  &&  (CurrentPersonScore  <=  30))
  8. {
  9. NewScoreStatus="Cold Lead";
  10. }
  11. else if((CurrentPersonScore  >  30)  &&  (CurrentPersonScore  <=  60))
  12. {
  13. NewScoreStatus="Warm Lead";
  14. }
  15. else if((CurrentPersonScore  >  60)  &&  (CurrentPersonScore  <=  90))
  16. {
  17. NewScoreStatus="Very Warm Lead";
  18. }
  19. else if(CurrentPersonScore  >  90)
  20. {
  21. NewScoreStatus="Hot Lead";
  22. }
  23. if(NewScoreStatus  !=  OldScoreStatus)
  24. {
  25. ScoreStatusAuditMap=map();
  26. ScoreStatusAuditMap.put("LeadID",CurrentLeadID);
  27. ScoreStatusAuditMap.put("New Status",NewScoreStatus);
  28. ScoreStatusAuditMap.put("Old Status",OldScoreStatus);
  29. ScoreStatusAuditMap.put("Date of Change",zoho.currenttime);
  30. updateResp = zoho.crm.create("CustomModule2",ScoreStatusAuditMap);
  31. LeadUpdateMap=map();
  32. LeadUpdateMap.put("Score Status",NewScoreStatus);
  33. updateResp = zoho.crm.updateRecord("Leads",CurrentLeadID,LeadUpdateMap);
  34. }
  35. }
When the workflow triggers:
  • The audit record gets written (with correct score status values for old and new), but with no lead (I have a lead lookup in the module)
  • The lead doesn't get updated with the new Score Status value .
What am I missing here??

Cheers
Jo