Skip to content

Instantly share code, notes, and snippets.

@CubeYogi
Last active November 12, 2020 08:37
Show Gist options
  • Save CubeYogi/a1a1b0a774718257b9c062840bdb7213 to your computer and use it in GitHub Desktop.
Save CubeYogi/a1a1b0a774718257b9c062840bdb7213 to your computer and use it in GitHub Desktop.
//Validating Ticket ID
if(ticket_id != null )
{
//Getting Ticket entry
//Replace your Organization ID for 'xxx'
ticket_entry = zoho.desk.getRecordById(xxx,"tickets",ticket_id);
//Validating Ticket entry
if(!ticket_entry.isEmpty())
{
//Getting Account ID
account_id = ticket_entry.get("accountId");
//Validating Account ID
if(account_id != null && account_id.trim() != "")
{
//Getting Account entry
//Replace your Organization ID for 'xxx'
account_entry = zoho.desk.getRecordById(xxx,"accounts",account_id);
//Validating Account entry
if(!account_entry.isEmpty() && account_entry.containKey("zohoCRMAccount"))
{
//Getting CRM Account ID
crm_map = account_entry.get("zohoCRMAccount");
crm_account_id = crm_map.get("id");
//Validating CRM Account ID
if(crm_account_id != null && crm_account_id.trim() != "")
{
//Putting values to create Deal
account_map = Map();
account_map.put("id", crm_account_id);
update_map = Map();
update_map.put("Account_Name", account_map);
ticket_subject = ticket_entry.get("subject");
update_map.put("Deal_Name", ticket_subject);
close_date = ifnull(ticket_entry.get("dueDate"),zoho.currentdate);
update_map.put("Closing_Date", close_date);
//Creating Deal entry
create_deal = zoho.crm.createRecord("Deals",update_map);
if(!create_deal.isEmpty() && create_deal.containKey("status") && create_deal.get("status") == "error")
{
info "Error in creating Deal: "+create_deal;
}
else
{
info "Deal created successfully";
}
}
else
{
info "CRM Account ID is empty";
}
}
else
{
info "Invalid Account response";
}
}
else
{
info "Invalid Account ID";
}
}
else
{
info "Invalid Ticket response";
}
}
else
{
info "Invalid Ticket ID passed";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment