Hi Zoho gurus,
During the migration of our old (SugarOnDemand) to Zoho CRM, I had several hundred calls and tasks that needed to be added to cover the gap in operations. However, a regular import could mess with the migration process - plus there is always a need to bring in tasks and calls. For example, set up tasks and call scheduled in support of external events.
I've created two Flows that may be useful for others. One for adding Tasks and the other for adding Scheduled calls. Currently, this flow monitors a Google Sheet (but you could set this up to be fired off any source) and adds a task or sheet for each new row. You could also hook this up to form or survey, etc.
I did NOT put error checking logic into this flow, as I knew all my data was clean.
To add such, you'd use decision blocks to check the ID of the various elements.
Flow: Add Task to a Contact, Account and Owner
These flows make use of a few custom deluge scripts, which are what this post is really all about. Here are the scripts.
Extract Account ID from a Contact Record
Why: The Account Name field on a fetched contact record is actually a map with both the name and the id. So you need to separate out the account's id in order to accurately fetch the full account record, and also to associate the account record to the Related To field of both Call and Task records.
string ExtractAccountID(string accountmap)
{
mp = Map();
mp = accountmap;
return mp.get("id");
}
ExtractAccountName
This is similar to the above, but instead of return the account id, it returns the account name.
string ExtractAccountName(string accountmap)
{
mp = Map();
mp = accountmap;
return mp.get("name");
}
Formatting Dates
Gawd! You need to be a rocket surgeon to work with dates in Zoho Deluge. I took to formatting the incoming dates in my sheet into two strictly formatted style: yyyy-MM-dd for dates and HH:mm:ss for time.
Even so, I still created a date formatter, so I would have only one place to make changes if I needed to.
string StringDateProcessor(string strdate, string strtime)
{
return strdate + "T" + strtime + "+11:00";
// following is other code I was messing about this... you get the idea.
//calctime = zoho.currenttime.addDay(1);
//return calctime.toString("yyyy-MM-dd'T'HH:mm:ss'+10:00'");
//toTime(datetimeString,"d,MM,yyyy hh:mm a","Australia/NSW");
}
Scheduling a Task
Now we get to the fun stuff! The actual scheduling. We have fetch the records we need (the user record to be the task owner, the contact record for the contact association on the task, and the account id which will be used on the Related To of the task.
I've placed comments throughout this code example so you know what's going on and why.
In addition, you'll see some custom fields (I've marked them in grey) that I had added to the tasks. You can just ignore these.
void SheduleTask(string name, string ownerid, string callstart, string contacttid, string phone, string mobile, string purpose, string accountid, string accountname)
{
// set up the map to hold the task information to be created
mp = Map();
// the subject name comes from the trigger app (in our case google sheets)
mp.put("Subject",name);
// the ownerid comes from the fetch user step of the flow.
mp.put("Owner",ownerid);
// the due date is a correctly formatted date in yyyy-MM-dd format - in this case from the trigger app
mp.put("Due_Date",callstart);
// these two fields are taken from fetched contact record - the contact record is found by the email address
mp.put("Phone",phone);
mp.put("Mobile",mobile);
// hard coded - this is scheduling calls, after all!
mp.put("Status","Scheduled");
mp.put("Priority","Low");
// another custom field, purpose, is passed from the trigger app
mp.put("Task_Purpose",purpose);
// the contacttid is the contact id and it comes from the fetched contact record
mp.put("Who_Id",contacttid);
// you need to use the map format to link the task to the Related To field of the account.
// You also need to set the $se_module to "Accounts"
accInfo = {"name":accountname,"id":accountid};
mp.put("$se_module","Accounts");
mp.put("What_Id",accInfo);
// now you create the new task record! FINALLY
create = zoho.crm.createRecord("Tasks",mp);
info mp;
info create;
}
Scheduling a Call
Scheduling a call is almost identical to the Task, but it needs a data time format (tasks only use date)
void SheduleACall(string name, string ownerid, string callstart, string contacttid, string purpose, string accountid, string accountname)
{
mp = Map();
mp.put("Subject",name);
mp.put("Owner",ownerid);
mp.put("Call_Start_Time",callstart);
mp.put("Call_Type","Outbound");
mp.put("Call_Purpose","Prospecting");
mp.put("Who_Id",contacttid);
accInfo = {"name":accountname,"id":accountid};
mp.put("$se_module","Accounts");
mp.put("What_Id",accInfo);
mp.put("$which_call","ScheduleCall");
create = zoho.crm.createRecord("Calls",mp);
info mp;
info create;
}
I hope this is useful. Enjoy!