patrickjust3k

Parsing Showingtime data

Jan 2nd, 2023
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. void parse_showingtime_data(int message_id)
  2. {
  3. if(message_id.isEven())
  4. {
  5. message_id = message_id + 1;
  6. }
  7. //decode mail body
  8. message_details = zoho.mail.getMessage(message_id,"zoho_flow_to_mail");
  9. //info message_details;
  10. mail_subject = message_details.get("SUBJECT");
  11. if(!mail_subject.isNull() && mail_subject.containsIgnoreCase("YOUR"))
  12. {
  13. showing_type = "buyer";
  14. }
  15. else
  16. {
  17. info "mail subject:" + mail_subject;
  18. HTML_text = message_details.get("CONTENT");
  19. if(input.HTML_text != "")
  20. {
  21. Output = HTML_text.replaceAll("  ","");
  22. Output = Output.replaceAll(" ","");
  23. Output = Output.replaceAll("<li","");
  24. Output = Output.replaceAll("<br>","");
  25. Output = Output.replaceAll("</p>","");
  26. Output = Output.replaceAll("<(.|\n)*?>","");
  27. Output = Output.replaceAll("\r\n","");
  28. Output = Output.replaceAll("\n","");
  29. Output = Output.replaceAll("\t","");
  30. Output = Output.getSuffix("Showing Confirmed");
  31. mail_body = Output.getPrefix("div.zm");
  32. //info mail_body;
  33. }
  34. // find MLS ID
  35. MLS_ID = mail_body.getSuffix("ID# ");
  36. MLS_ID = MLS_ID.substring(0,7);
  37. info "MLS #: " + MLS_ID;
  38. //find crm record associated with that MLS number
  39. query = "(MLS_Num:equals:" + MLS_ID + ")";
  40. deal_search = zoho.crm.searchRecords("Deals",query);
  41. number_of_deals = deal_search.size();
  42. info "matching # of deals: " + number_of_deals;
  43. //find the id of deal record if there is one matching
  44. for each deal in deal_search
  45. {
  46. deal_id = deal_search.getJSON("id");
  47. info "deal_id: " + deal_id;
  48. }
  49. //enter Patrick for deal owner if no deal id
  50. deal_owner_id = "4933226000000350001";
  51. //else search for deal owner id and use for inquiry owner
  52. if(!deal_id.isNull())
  53. {
  54. deal_details = zoho.crm.getRecordById("Deals",deal_id);
  55. deal_owner_name = deal_details.getJSON("Owner").get("name");
  56. deal_owner_id = deal_details.getJSON("Owner").get("id");
  57. info "deal owner id: " + deal_owner_id;
  58. }
  59. //find date
  60. date = mail_body.getSuffixIgnoreCase("Appointment Details");
  61. date = date.getSuffixIgnoreCase("Showing");
  62. date = date.getPrefixIgnoreCase("-");
  63. date = date.toString();
  64. date = date.getSuffixIgnoreCase(",");
  65. //convert date to correct format
  66. date = replaceAll(date,"January","01,");
  67. date = replaceAll(date,"Februaru","02,");
  68. date = replaceAll(date,"March","03,");
  69. date = replaceAll(date,"April","04,");
  70. date = replaceAll(date,"May","05,");
  71. date = replaceAll(date,"June","06,");
  72. date = replaceAll(date,"July","07,");
  73. date = replaceAll(date,"August","08,");
  74. date = replaceAll(date,"September","09,");
  75. date = replaceAll(date,"October","10,");
  76. date = replaceAll(date,"November","11,");
  77. date = replaceAll(date,"December","12,");
  78. date = replaceAll(date,"PM","");
  79. date = replaceAll(date,"AM","");
  80. date = date.subString(0,14);
  81. showing_date = toDate(date,"MM,dd,yyyy");
  82. info "converted date : " + showing_date;
  83. //get buyer agent info
  84. buyer_agent_section = mail_body.getSuffix("Buyer's Agent Details");
  85. buyer_agent_section = buyer_agent_section.getPrefix("Listing Contacts");
  86. buyer_agent_section = buyer_agent_section.trim();
  87. buyer_agent_name = buyer_agent_section.subString(0,24);
  88. buyer_agent_name = buyer_agent_name.trim();
  89. info "buyer agent name: " + buyer_agent_name;
  90. //get buyer agent phone
  91. buyer_agent_phone = buyer_agent_section.getSuffix("(");
  92. buyer_agent_phone = buyer_agent_phone.removeFirstOccurence(")");
  93. buyer_agent_phone = buyer_agent_phone.replaceAllIgnoreCase(" ","-");
  94. buyer_agent_phone = buyer_agent_phone.subString(0,12);
  95. info "buyer agent phone: " + buyer_agent_phone;
  96. //get buyer agent email
  97. buyer_agent_email = buyer_agent_section.getSuffixIgnoreCase("(Office Main Line)");
  98. buyer_agent_email = buyer_agent_email.trim();
  99. info "buyer agent email: " + buyer_agent_email;
  100. //build map and create inquiry
  101. inquiry_map = Map();
  102. inquiry_map.put("Name",buyer_agent_name);
  103. inquiry_map.put("Date_1",showing_date);
  104. inquiry_map.put("Inquired_on",{"id":deal_id});
  105. inquiry_map.put("Source","ShowingTime");
  106. inquiry_map.put("Owner",{"id":deal_owner_id});
  107. inquiry_map.put("Status","Showed");
  108. inquiry_map.put("Phone_1",buyer_agent_phone);
  109. inquiry_map.put("Email",buyer_agent_email);
  110. create_inquiry = zoho.crm.createRecord("Inquiry",inquiry_map);
  111. info create_inquiry;
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment