Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get mail record
- mailDetails = zoho.crm.getRecordById("mail_data",mailId.toLong());
- //get subject and body
- mail_subject = ifnull(mailDetails.get("Subject"),"");
- mail_body = ifnull(mailDetails.get("MailBody"),"");
- //info "mail body : " + mail_body;
- //info "mail subject: " + mail_subject;
- //get address
- address = mail_subject.substring(20);
- address = address.getPrefix(",");
- address = address.subString(0,10);
- info "address : " + address;
- //get date from email body
- date_long = mail_body.getSuffixIgnoreCase("Appointment Details");
- date_after_showing = date_long.getSuffixIgnoreCase("Showing");
- date_before_dash = date_after_showing.getPrefixIgnoreCase("-");
- date_tostring = date_before_dash.toString();
- date = date_tostring.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);
- date = toDate(date,"MM,dd,yyyy");
- info "converted date : " + date;
- // get buyer agent name
- buyer_agent = mail_body.getSuffix("Buyer's Agent Details");
- buyer_agent = buyer_agent.subString(0,22);
- info "buyer agent: " + buyer_agent;
- //get buyer agent phone number
- buyer_phone = mail_body.getSuffix("Buyer's Agent Details");
- buyer_phone = mail_body.getSuffix("(");
- buyer_phone = buyer_phone.removeFirstOccurence(")");
- buyer_phone = buyer_phone.replaceAllIgnoreCase(" ","-");
- buyer_phone = buyer_phone.subString(0,12);
- info "buyer phone : " + buyer_phone;
- //get buyer agent email
- buyer_email = mail_body.getSuffixIgnoreCase("(Office Main Line)");
- buyer_email = buyer_email.getPrefixIgnoreCase("Listing");
- info "buyer email : " + buyer_email;
- //find deal id mathcing address
- deal_search = zoho.crm.searchRecords("Deals","Deal_Address:starts_with:" + address);
- //info "deal --- > " + deal_search;
- if(deal_search.isEmpty())
- {
- sendmail
- [
- from :zoho.adminuserid
- to :"[email protected]"
- subject :"Function loading showingtime into Zoho is broken"
- message :"<div>The function for loading showingtime info into zoho is broken.</div>"
- ]
- }
- else
- {
- deal_id = deal_search.getJSON("id");
- deal_details = zoho.crm.getRecordById("Deals",deal_id);
- deal_owner = deal_details.getJSON("Owner").get("id");
- info "deal owner: " + deal_owner;
- info "deal id: " + deal_id;
- mailmap = Map();
- mailmap.put("Name",ifnull(buyer_agent,""));
- mailmap.put("Date_1",ifnull(date,""));
- mailmap.put("Phone_1",buyer_phone);
- mailmap.put("Inquiries Owner",ifnull("Patrick Kaiser",""));
- mailmap.put("Email",ifnull(buyer_email,""));
- mailmap.put("Inquired_on",{"id":deal_id});
- mailmap.put("Source","ShowingTime");
- mailmap.put("Status","Showed");
- mailcreate = zoho.crm.createRecord("Inquiry",mailmap);
- info mailcreate;
- }
Advertisement
Add Comment
Please, Sign In to add comment