Check POP if Already with the Same Unit
Wed Jul 30 2025 05:29:08 GMT+0000 (Coordinated Universal Time)
Saved by @Peaky ##pagination ##zoho ##zohocrm ##zoho_crm ##deluge
entityMap = crmAPIRequest.toMap().get("record"); response = Map(); Unit_ID = ifNull(entityMap.get("Unit_No"),{"id":""}).get("id"); current_Sales_Type_Identification = ifnull(entityMap.get("Sales_Type_Identification"),""); current_POP_Status = ifnull(entityMap.get("Pick_List_1"),""); Edit_Record = ifNull(entityMap.get("Edit_Record"),""); if(Edit_Record == false) { if(Unit_ID != "") { if(current_Sales_Type_Identification == "New Sale") { Unit_name = ifNull(entityMap.get("Unit_No"),{"name":""}).get("name"); search_resp = zoho.crm.searchRecords("POP","(Unit_No:equals:" + Unit_name + ")"); if(search_resp.size() > 0) { for each pop in search_resp { existing_Pop_status = ifnull(pop.get("Pick_List_1"),""); info "existing Pop_status ==>" + existing_Pop_status; existing_Sales_Type_Identification = ifnull(pop.get("Sales_Type_Identification"),""); info "existing_Sales_Type_Identification ==>" + existing_Sales_Type_Identification; if(existing_Sales_Type_Identification == "New Sale") { if(existing_Pop_status == "Payment Lost") { response.put('status','success'); } else { response.put('status','error'); response.put('message','An POP with Same Unit No already exist in systen'); break; } } else if(existing_Sales_Type_Identification == "Existing Sale") { get_salestracker_records = zoho.crm.getRelatedRecords("Sales_Tracker","Products",Unit_ID); for each record in get_salestracker_records { Cancelled_Units_Yes_No = ifnull(record.get("Cancelled_Units_Yes_No"),""); if(Cancelled_Units_Yes_No != "Yes") { response.put('status','error'); response.put('message','An active reservation already associated with this Unit.'); break; } else if(Cancelled_Units_Yes_No == "Yes") { response.put('status','success'); } } } } } else { get_salestracker_records = zoho.crm.getRelatedRecords("Sales_Tracker","Products",Unit_ID); for each record in get_salestracker_records { Cancelled_Units_Yes_No = ifnull(record.get("Cancelled_Units_Yes_No"),""); if(Cancelled_Units_Yes_No != "Yes") { response.put('status','error'); response.put('message','An active reservation already associated with this Unit.'); break; } else if(Cancelled_Units_Yes_No == "Yes") { response.put('status','success'); } } } } else if(current_Sales_Type_Identification == "Existing Sale") { // get_salestracker_records = zoho.crm.getRelatedRecords("Sales_Tracker","Products",Unit_ID); // if(get_salestracker_records.size() > 0) // { // for each record in get_salestracker_records // { // Cancelled_Units_Yes_No = ifnull(record.get("Cancelled_Units_Yes_No"),""); // if(Cancelled_Units_Yes_No != "Yes") // { // response.put('status','error'); // response.put('message','An active reservation already associated with this Unit.'); // break; // } // else if(Cancelled_Units_Yes_No == "Yes") // { // response.put('status','success'); // } // } // } // else // { // response.put('status','success'); // } response.put('status','success'); } } } if(response.isEmpty()) { response.put('status','success'); } return response;
Comments