salesOrderresp = zoho.crm.getRecordById("Sales_Orders",salesorderId); if(salesOrderresp != null) { Summary = salesOrderresp.get("Subject"); Account_Name = salesOrderresp.get("Account_Name").toMap().get("name"); Encoded_Account_Name = zoho.encryption.urlEncode(Account_Name); response = invokeurl [ url :"https://fsm.zoho.com/fsm/v1/Companies/search?api_name=Company_Name&value=" + Encoded_Account_Name type :GET connection:"fsmconnection" ]; if(response != "") { response_data = response.get("data").toMap(); FSM_Account_id = response_data.get("id"); Billing_Address_resp = response_data.get("Billing_Address"); if(Billing_Address_resp != null) { Billing_Address_resp = Billing_Address_resp.toMap(); bill_add_map = Map(); bill_add_map.put("id",Billing_Address_resp.get("id")); } Service_Address_resp = response_data.get("Service_Address"); if(Service_Address_resp != null) { Service_Address_resp = Service_Address_resp.toMap(); ship_add_map = Map(); ship_add_map.put("id",Service_Address_resp.get("id")); } } else { Account_Id = salesOrderresp.get("Account_Name").toMap().get("id"); account_resp = zoho.crm.getRecordById("Accounts",Account_Id); mobile = account_resp.get("Fax"); phone = account_resp.get("Phone"); website = account_resp.get("Website"); sh_street = account_resp.get("Shipping_Street"); sh_city = account_resp.get("Shipping_City"); sh_state = account_resp.get("Shipping_State"); sh_code = account_resp.get("Shipping_Code"); sh_country = account_resp.get("Shipping_Country"); bi_street = account_resp.get("Billing_Street"); bi_city = account_resp.get("Billing_City"); bi_state = account_resp.get("Billing_State"); bi_code = account_resp.get("Billing_Code"); bi_country = account_resp.get("Billing_Country"); createMap = Map(); createMap.put("Company_Name",Account_Name); createMap.put("Mobile",mobile); createMap.put("Phone",phone); createMap.put("Website",website); Service_Address_Map = Map(); Service_Address_Map.put("Address_Name",Account_Name + "Shipping Address"); Service_Address_Map.put("Street_1",sh_street); Service_Address_Map.put("City",sh_city); Service_Address_Map.put("State",sh_state); Service_Address_Map.put("Zip_Code",sh_code); Service_Address_Map.put("Country",sh_country); Billing_Address_Map = Map(); Billing_Address_Map.put("Address_Name",Account_Name + "Billing Address"); Billing_Address_Map.put("Street_1",bi_street); Billing_Address_Map.put("City",bi_city); Billing_Address_Map.put("State",bi_state); Billing_Address_Map.put("Zip_Code",bi_code); Billing_Address_Map.put("Country",bi_country); createMap.put("Service_Address",Service_Address_Map); createMap.put("Billing_Address",Billing_Address_Map); responze = zoho.fsm.createRecord("Companies",createMap); FSM_Account_id = responze.get("data").toMap().get("Companies").toMap().get("id"); temp_company_resp = zoho.fsm.getRecordById("Companies",FSM_Account_id); response_data_x = temp_company_resp.get("data").toMap(); Billing_Address_resp = response_data_x.get("Billing_Address"); if(Billing_Address_resp != null) { Billing_Address_resp = Billing_Address_resp.toMap(); bill_add_map = Map(); bill_add_map.put("id",Billing_Address_resp.get("id")); } Service_Address_resp = response_data_x.get("Service_Address"); if(Service_Address_resp != null) { Service_Address_resp = Service_Address_resp.toMap(); ship_add_map = Map(); ship_add_map.put("id",Service_Address_resp.get("id")); } } Contact_Id = salesOrderresp.get("Contact_Name").toMap().get("id"); Contact_Resp = zoho.crm.getRecordById("Contacts",Contact_Id); Contact_Email = Contact_Resp.get("Email"); responze = invokeurl [ url :"https://fsm.zoho.com/fsm/v1/Contacts/search?api_name=Email&value=" + Contact_Email type :GET connection:"fsmconnection" ]; if(responze.toString() != "") { responze = responze.toMap(); FSM_Contact_id = responze.get("data").toMap().get("id"); } else { Salutation = Contact_Resp.get("Salutation"); First_Name = Contact_Resp.get("First_Name"); Last_Name = Contact_Resp.get("Last_Name"); Phone = Contact_Resp.get("Phone"); Mobile = Contact_Resp.get("Mobile"); bi_Street = Contact_Resp.get("Mailing_Street"); bi_city = Contact_Resp.get("Mailing_City"); bi_state = Contact_Resp.get("Mailing_State"); bi_code = Contact_Resp.get("Mailing_Zip"); bi_country = Contact_Resp.get("Mailing_Country"); sh_street = Contact_Resp.get("Other_Street"); sh_city = Contact_Resp.get("Other_City"); sh_state = Contact_Resp.get("Other_State"); sh_code = Contact_Resp.get("Other_Zip"); sh_country = Contact_Resp.get("Other_Country"); createMap = Map(); createMap.put("Salutation",Salutation); createMap.put("First_Name",First_Name); createMap.put("Last_Name",Last_Name); createMap.put("Email",Contact_Email); createMap.put("Phone",Phone); createMap.put("Mobile",Mobile); createMap.put("Company",FSM_Account_id); Service_Address_Map = Map(); Service_Address_Map.put("Address_Name",First_Name + " " + Last_Name + " Shipping Address"); Service_Address_Map.put("Street_1",sh_street); Service_Address_Map.put("City",sh_city); Service_Address_Map.put("State",sh_state); Service_Address_Map.put("Zip_Code",sh_code); Service_Address_Map.put("Country",sh_country); Billing_Address_Map = Map(); Billing_Address_Map.put("Address_Name",First_Name + " " + Last_Name + " Billing Address"); Billing_Address_Map.put("Street_1",bi_Street); Billing_Address_Map.put("City",bi_city); Billing_Address_Map.put("State",bi_state); Billing_Address_Map.put("Zip_Code",bi_code); Billing_Address_Map.put("Country",bi_country); createMap.put("Service_Address",Service_Address_Map); createMap.put("Billing_Address",Billing_Address_Map); cr_resp = zoho.fsm.createRecord("Contacts",createMap); FSM_Contact_id = cr_resp.get("data").toMap().get("Contacts").toMap().get("id"); } i = 1; servive_line_list = list(); product_List = salesOrderresp.get("Product_Details").toList(); for each each_product in product_List { temp_each_product = each_product.toMap(); quantity = temp_each_product.get("quantity"); unit_price = temp_each_product.get("unit_price"); product_Name = temp_each_product.get("product").toMap().get("name"); Encoded_product_Name = zoho.encryption.urlEncode(product_Name); rezponse = invokeurl [ url :"https://fsm.zoho.com/fsm/v1/Service_And_Parts/search?api_name=Name&value=" + Encoded_product_Name type :GET connection:"fsmconnection" ]; if(rezponse != "") { FSM_Product_id = rezponse.get("data").toMap().get("id"); } else { product_id = each_product.toMap().get("product").toMap().get("id"); product_resp = zoho.crm.getRecordById("Products",product_id); Unit = product_resp.get("Usage_Unit"); Unit_Price = product_resp.get("Unit_Price"); Type = product_resp.get("Product_Category"); Description = product_resp.get("Description"); createMap = Map(); createMap.put("Name",product_Name); createMap.put("Description",Description); createMap.put("Unit",Unit); createMap.put("Unit_Price",Unit_Price); createMap.put("Type",Type); resp = zoho.fsm.createRecord("Service_And_Parts",createMap); FSM_Product_id = resp.get("data").toMap().get("Service_And_Parts").toMap().get("id"); } servive_line_resp = Map(); servive_line_resp.put("Service",FSM_Product_id); servive_line_resp.put("Quantity",quantity); servive_line_resp.put("List_Price",unit_price); servive_line_resp.put("Sequence",i); servive_line_list.add(servive_line_resp); i = i + 1; } } terrResp = zoho.fsm.getRecords("Territories"); terrId = terrResp.get("data").toMap().get("id"); createMap = Map(); createMap.put("Summary",Summary); createMap.put("Priority","Medium"); createMap.put("Type","Service"); createMap.put("Contact",FSM_Contact_id); createMap.put("Company",FSM_Account_id); createMap.put("Service_Address",ship_add_map); createMap.put("Billing_Address",bill_add_map); createMap.put("Service_Line_Items",servive_line_list); createMap.put("Territory",terrId); create_resp = zoho.fsm.createRecord("Work_Orders",createMap); info create_resp; |
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.