Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void parse_showingtime_data(int message_id)
- {
- //decode mail body
- message_details = zoho.mail.getMessage(message_id,"zoho_flow_to_mail");
- //info message_details;
- mail_subject = message_details.get("SUBJECT");
- if(!mail_subject.isNull() && mail_subject.containsIgnoreCase("YOUR"))
- {
- showing_type = "buyer";
- }
- else
- {
- info "mail subject:" + mail_subject;
- HTML_text = message_details.get("CONTENT");
- if(input.HTML_text != "")
- {
- Output = HTML_text.replaceAll(" ","");
- Output = Output.replaceAll(" ","");
- Output = Output.replaceAll("<li","");
- Output = Output.replaceAll("<br>","");
- Output = Output.replaceAll("</p>","");
- Output = Output.replaceAll("<(.|\n)*?>","");
- Output = Output.replaceAll("\r\n","");
- Output = Output.replaceAll("\n","");
- Output = Output.replaceAll("\t","");
- Output = Output.getSuffix("Showing Confirmed");
- mail_body = Output.getPrefix("div.zm");
- //info mail_body;
- }
- // find MLS ID
- MLS_ID = mail_body.getSuffix("ID# ");
- MLS_ID = MLS_ID.substring(0,7);
- info "MLS #: " + MLS_ID;
- //find crm record associated with that MLS number
- query = "(MLS_Num:equals:" + MLS_ID + ")";
- deal_search = zoho.crm.searchRecords("Deals",query);
- number_of_deals = deal_search.size();
- info "matching # of deals: " + number_of_deals;
- //find the id of deal record if there is one matching
- for each deal in deal_search
- {
- deal_id = deal_search.getJSON("id");
- info "deal_id: " + deal_id;
- }
- //enter Patrick for deal owner if no deal id
- deal_owner_id = "4933226000000350001";
- //else search for deal owner id and use for inquiry owner
- if(!deal_id.isNull())
- {
- deal_details = zoho.crm.getRecordById("Deals",deal_id);
- deal_owner_name = deal_details.getJSON("Owner").get("name");
- deal_owner_id = deal_details.getJSON("Owner").get("id");
- info "deal owner id: " + deal_owner_id;
- }
- //find date
- date = mail_body.getSuffixIgnoreCase("Appointment Details");
- date = date.getSuffixIgnoreCase("Showing");
- date = date.getPrefixIgnoreCase("-");
- date = date.toString();
- date = date.getSuffixIgnoreCase(",");
- //convert date to correct format
- date = replaceAll(date,"January","01,");
- date = replaceAll(date,"Februaru","02,");
- date = replaceAll(date,"March","03,");
- date = replaceAll(date,"April","04,");
- date = replaceAll(date,"May","05,");
- date = replaceAll(date,"June","06,");
- date = replaceAll(date,"July","07,");
- date = replaceAll(date,"August","08,");
- date = replaceAll(date,"September","09,");
- date = replaceAll(date,"October","10,");
- date = replaceAll(date,"November","11,");
- date = replaceAll(date,"December","12,");
- date = replaceAll(date,"PM","");
- date = replaceAll(date,"AM","");
- date = date.subString(0,14);
- showing_date = toDate(date,"MM,dd,yyyy");
- info "converted date : " + showing_date;
- //get buyer agent info
- buyer_agent_section = mail_body.getSuffix("Buyer's Agent Details");
- buyer_agent_section = buyer_agent_section.trim();
- buyer_agent_name = buyer_agent_section.subString(0,24);
- buyer_agent_name = buyer_agent_name.trim();
- info "buyer agent name: " + buyer_agent_name;
- //get buyer agent phone
- buyer_agent_phone = buyer_agent_section.getSuffix("(");
- buyer_agent_phone = buyer_agent_phone.removeFirstOccurence(")");
- buyer_agent_phone = buyer_agent_phone.replaceAllIgnoreCase(" ","-");
- buyer_agent_phone = buyer_agent_phone.subString(0,12);
- info "buyer agent phone: " + buyer_agent_phone;
- //get buyer agent email
- buyer_agent_email = buyer_agent_section.getSuffixIgnoreCase("(Office Main Line)");
- buyer_agent_email = buyer_agent_email.trim();
- info "buyer agent email: " + buyer_agent_email;
- //build map and create inquiry
- inquiry_map = Map();
- inquiry_map.put("Name",buyer_agent_name);
- inquiry_map.put("Date_1",showing_date);
- inquiry_map.put("Inquired_on",{"id":deal_id});
- inquiry_map.put("Source","ShowingTime");
- inquiry_map.put("Owner",{"id":deal_owner_id});
- inquiry_map.put("Status","Showed");
- inquiry_map.put("Phone_1",buyer_agent_phone);
- inquiry_map.put("Email",buyer_agent_email);
- create_inquiry = zoho.crm.createRecord("Inquiry",inquiry_map);
- info create_inquiry;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement