Public URL for Writer Merge

Public URL for Writer Merge

I'm trying to do a merge with images, but am getting stuck on the public url needed.

I created this workflow to get an image field (public_url) I can use outside of Zoho (in a Writer merge template). It work's in Zoho Creator also, but not on the merge (still the placeholder image with an error, and takes forever to load this). What did I miss?

Status_Picklist = form with only Rating and Rating_Image (like Product and Product_Image
All_Status = public report for Status_Picklist
Inpsection_Report = form with lookup field for Status_Picklist where output is (not a report--the form is called a report in the industry lol) 
Grading_and_Drainage_Status = the Rating lookup field in Inspection_Report
Note--selecting above successfully returns the correct image in an Image field and Public URL image field inside Zoho Creator
Public URL = the image field I'm trying to populate the public URL into and using for merge. 
  1. //get image records records and save as variable name publicurl
  2. publicurl = Status_Picklist[ID == input.Grading_and_Drainage_Status].Rating_Image;

  3. //extract record ID
  4. myID = Status_Picklist [ ID = input.Grading_and_Drainage_Status].ID;

  5. //create variable for encrypted key
  6. encryptedKey = "5vAx1bRSnKB5zYnYgs0UvRB46bmZ0NthqjEYsjtD91aCawrPBBfDu8kTu44yW8YCDSG4aXwWCmmssbeX7WRmM8AWrDjbmgy2TbzK";

  7. //extract image file name from record
  8. filename = publicurl.getsuffix("image/").getprefix("\" border").trim();

  9. //modify URL
  10. if(publicurl != null)
  11. {
  12. publicurl = publicurl.replaceALL("creatorexport.zoho.com","creator.zohopublic.com");
  13. publicurl = publicurl.replaceALL("/sharedBy/appLinkName/",zoho.appuri);
  14. publicurl = publicurl.replaceALL("viewLinkName","All_Status");
  15. publicurl = publicurl.replaceALL("fieldName",myID.toString());
  16. publicurl = publicurl.replaceALL("image/","Rating_Image/image-download/" + encryptedKey +"/" + filename);
  17. publicurl = publicurl.replaceAll("<img","<img height=51px width=144px");
  18. }
  19. input.public_url = publicurl;