string button.CreateRequestInFSM(String deal_id) { dealResp = zoho.crm.getRecordById("Deals",deal_id); Tax_Id = "5391129000000473001"; // replace the TAX ID from the Books Tax_name = "us"; // replace the TAX Name from the Books tax_percentage = 23; // replace the TAX Percentage from the Books tax = {"Taxable":true,"Tax_Percentage":tax_percentage,"Tax_Name":Tax_name,"Tax_Id":Tax_Id}; erroravailable = false; errormessage = ""; //info dealResp; if(dealResp != null) { Summary = dealResp.get("Deal_Name"); Account = dealResp.get("Account_Name"); AccountId = ""; //info Account; if(Account != null && Account != "" && Account.containKey("id")) { AccountId = Account.get("id"); Company_name = Account.get("name"); //info AccountId; Account_resp = zoho.crm.getRecordById("Accounts",AccountId).toMap(); Account_map = Account_resp.toMap(); //info Account_map; Contact_Email = Account_map.get("Email"); bl_address = Account_map.get("Billing_Street"); bl_city = Account_map.get("Billing_City"); bl_country = Account_map.get("Billing_Country"); bl_state = Account_map.get("Billing_State"); bl_zip = Account_map.get("Billing_Code"); sh_address = Account_map.get("Shipping_Street"); sh_city = Account_map.get("Shipping_City"); sh_country = Account_map.get("Shipping_Country"); sh_state = Account_map.get("Shipping_State"); sh_zip = Account_map.get("Shipping_Code"); } if(Company_name.toString() != "" && Company_name != null) { //info response; response = zoho.fsm.searchRecordsByField("Companies","ZCRM_Id",AccountId,Map(),"fsmconnection"); info response; if(response.isNull() || response.isEmpty()) { response = zoho.fsm.searchRecordsByField("Companies","Company_Name",Company_name,Map(),"fsmconnection"); } //info response; if(response.toString() != "" && response != null) { list_item = response.get("data").get(0); serviceAdId = ""; billingAdId = ""; //info list_item; fsmCust = list_item.get("Company_Name"); if(fsmCust.equalsIgnoreCase(Company_name)) { fsm_Company_id = list_item.get("id"); //info fsm_customer_id; Billing_Address = list_item.get("Billing_Address"); Service_Address = list_item.get("Service_Address"); if(Service_Address != null) { serviceAdId = Service_Address.get("id"); } if(Billing_Address != null) { billingAdId = Billing_Address.get("id"); } if(serviceAdId == "" && billingAdId != "") { serviceAdId = billingAdId; } else if(billingAdId == "" && serviceAdId != "") { billingAdId = serviceAdId; } else if(serviceAdId == "" && billingAdId == "") { Service_Address_Map = Map(); Service_Address_Map.put("Address_Name",Company_name + " Shipping Address"); Service_Address_Map.put("Street_1",sh_address); Service_Address_Map.put("City",sh_city); Service_Address_Map.put("State",sh_state); Service_Address_Map.put("Zip_Code",sh_zip); Service_Address_Map.put("Country",sh_country); Billing_Address_Map = Map(); Billing_Address_Map.put("Address_Name",Company_name + " Billing Address"); Billing_Address_Map.put("Street_1",bl_address); Billing_Address_Map.put("City",bl_city); Billing_Address_Map.put("State",bl_state); Billing_Address_Map.put("Zip_Code",bl_zip); Billing_Address_Map.put("Country",bl_country); response = zoho.fsm.updateRecord("Companies",fsm_Company_id,{"Service_Address":Service_Address_Map,"Billing_Address":Billing_Address_Map}); con_response = zoho.fsm.getRecordById("Companies",fsm_Company_id).toMap(); sample = con_response.get("data").get(0); if(sample.get("Service_Address") != null) { serviceAdId = sample.get("Service_Address").get("id"); } if(sample.get("Billing_Address") != null) { billingAdId = sample.get("Billing_Address").get("id"); } } } } else { Phone = Account_resp.get("Phone"); createMap = Map(); createMap.put("Company_Name",Company_name); createMap.put("Phone",Phone); createMap.put("Tax",tax); Service_Address_Map = Map(); Service_Address_Map.put("Address_Name",Company_name + " Shipping Address"); Service_Address_Map.put("Street_1",sh_address); Service_Address_Map.put("City",sh_city); Service_Address_Map.put("State",sh_state); Service_Address_Map.put("Zip_Code",sh_zip); Service_Address_Map.put("Country",sh_country); Billing_Address_Map = Map(); Billing_Address_Map.put("Address_Name",Company_name + " Billing Address"); Billing_Address_Map.put("Street_1",bl_address); Billing_Address_Map.put("City",bl_city); Billing_Address_Map.put("State",bl_state); Billing_Address_Map.put("Zip_Code",bl_zip); Billing_Address_Map.put("Country",bl_country); createMap.put("Service_Address",Service_Address_Map); createMap.put("Billing_Address",Billing_Address_Map); cr_resp = zoho.fsm.createRecord("Companies",createMap); fsm_Company_id = cr_resp.get("data").toMap().get("Companies").toMap().get("id"); response = zoho.fsm.getRecordById("Companies",fsm_Company_id); //info response; billingAdId = response.get("data").toMap().get("Billing_Address").toMap().get("id"); serviceAdId = response.get("data").toMap().get("Service_Address").toMap().get("id"); } } Contact = dealResp.get("Contact_Name"); //info Contact; Contact_Email = ""; if(Contact != null && Contact != "" && Contact.containKey("id")) { Contact_id = Contact.get("id"); Contact_name = Contact.get("name"); //info AccountId; customer_resp = zoho.crm.getRecordById("Contacts",Contact_id).toMap(); customer_map = customer_resp.toMap(); Contact_Email = customer_map.get("Email"); bl_address = customer_map.get("Billing_Street"); bl_city = customer_map.get("Billing_City"); bl_country = customer_map.get("Billing_Country"); bl_state = customer_map.get("Billing_State"); bl_zip = customer_map.get("Billing_Code"); sh_address = customer_map.get("Shipping_Street"); sh_city = customer_map.get("Shipping_City"); sh_country = customer_map.get("Shipping_Country"); sh_state = customer_map.get("Shipping_State"); sh_zip = customer_map.get("Shipping_Code"); //info customer_map; if(!Contact_id.isNull() && !Contact_id.isEmpty()) { serviceAdId = ""; billingAdId = ""; response = zoho.fsm.searchRecordsByField("Contacts","ZCRM_Id",Contact_id,Map(),"fsmconnection"); info response; if(response.isNull() || response.isEmpty()) { if(!Contact_Email.isNull() && !Contact_Email.isEmpty()) { response = zoho.fsm.searchRecordsByField("Contacts","Email",Contact_Email,Map(),"fsmconnection"); } } //info response; if(response.toString() != "" && response != null) { list_item = response.get("data").get(0); serviceAdId = ""; billingAdId = ""; //info list_item; fsm_customer_id = list_item.get("id"); Billing_Address = list_item.get("Billing_Address"); Service_Address = list_item.get("Service_Address"); if(Service_Address != null) { serviceAdId = Service_Address.get("id"); } if(Billing_Address != null) { billingAdId = Billing_Address.get("id"); } if(serviceAdId == "" && billingAdId != "") { serviceAdId = billingAdId; } else if(billingAdId == "" && serviceAdId != "") { billingAdId = serviceAdId; } else if(serviceAdId == "" && billingAdId == "") { Service_Address_Map = Map(); Service_Address_Map.put("Address_Name",Contact_name + " Shipping Address"); Service_Address_Map.put("Street_1",sh_address); Service_Address_Map.put("City",sh_city); Service_Address_Map.put("State",sh_state); Service_Address_Map.put("Zip_Code",sh_zip); Service_Address_Map.put("Country",sh_country); Billing_Address_Map = Map(); Billing_Address_Map.put("Address_Name",Contact_name + " Billing Address"); Billing_Address_Map.put("Street_1",bl_address); Billing_Address_Map.put("City",bl_city); Billing_Address_Map.put("State",bl_state); Billing_Address_Map.put("Zip_Code",bl_zip); Billing_Address_Map.put("Country",bl_country); response = zoho.fsm.updateRecord("Contacts",fsm_customer_id,{"Service_Address":Service_Address_Map,"Billing_Address":Billing_Address_Map}); //info response; con_response = zoho.fsm.getRecordById("Contacts",fsm_customer_id).toMap(); sample = con_response.get("data").get(0); if(sample.get("Service_Address") != null) { serviceAdId = sample.get("Service_Address").get("id"); } if(sample.get("Billing_Address") != null) { billingAdId = sample.get("Billing_Address").get("id"); } } } else { Phone = customer_resp.get("Phone"); createMap = Map(); createMap.put("Last_Name",Contact_name); createMap.put("Email",Contact_Email); createMap.put("Phone",Phone); createMap.put("Tax",tax); Service_Address_Map = Map(); Service_Address_Map.put("Address_Name",Contact_name + " Shipping Address"); Service_Address_Map.put("Street_1",sh_address); Service_Address_Map.put("City",sh_city); Service_Address_Map.put("State",sh_state); Service_Address_Map.put("Zip_Code",sh_zip); Service_Address_Map.put("Country",sh_country); Billing_Address_Map = Map(); Billing_Address_Map.put("Address_Name",Contact_name + " Billing Address"); Billing_Address_Map.put("Street_1",bl_address); Billing_Address_Map.put("City",bl_city); Billing_Address_Map.put("State",bl_state); Billing_Address_Map.put("Zip_Code",bl_zip); Billing_Address_Map.put("Country",bl_country); createMap.put("Service_Address",Service_Address_Map); createMap.put("Billing_Address",Billing_Address_Map); cr_resp = zoho.fsm.createRecord("Contacts",createMap); //info cr_resp; fsm_customer_id = cr_resp.get("data").toMap().get("Contacts").toMap().get("id"); response = zoho.fsm.getRecordById("Contacts",fsm_customer_id); //info response; billingAdId = response.get("data").toMap().get("Billing_Address").toMap().get("id"); serviceAdId = response.get("data").toMap().get("Service_Address").toMap().get("id"); } terrResp = zoho.fsm.getRecords("Territories"); terrId = terrResp.get("data").toMap().get("id"); createMap = Map(); createMap.put("Summary",Summary); createMap.put("Company",fsm_Company_id); createMap.put("Contact",fsm_customer_id); createMap.put("Service_Address",{"id":serviceAdId}); createMap.put("Billing_Address",{"id":billingAdId}); createMap.put("Territory",terrId); info createMap; } } else { erroravailable = true; errormessage = "Contacts is Mandatory for workorder creation"; } } if(erroravailable == false) { create_resp = zoho.fsm.createRecord("Requests",createMap); reqId = create_resp.get("data").toMap().get("Requests").toMap().get("id"); api_url = "https://fsm.zoho.com/fsm/v1/Requests/" + reqId + "/actions/process_sync?sync_service=zohocrm"; // Update the link to the based on the DC. // Define the body request_body = Map(); data_list = List(); data_item = Map(); data_item.put("integ_id",deal_id); data_item.put("sync_process","link"); data_item.put("integ_module","Deals"); data_list.add(data_item); request_body.put("data",data_list); // Convert the body to JSON string request_body_json = request_body.toString(); link_res = invokeurl [ url :api_url type :POST parameters:request_body_json connection:"fsmconnection" ]; } else { info errormessage; /* sendmail [ from: zoho.adminuserid to: zoho.adminuserid subject: "Request is not created" message: errormessage ] */ } return "Function executed successfully"; } |
Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.
If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.
You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.