Welcome to Portal

?Unknown\pull-down

Welcome to Zoho Cares

Bienvenido a Soporte de Zoho

Search our knowledge base, ask the community or submit a request.

Hello,

I am currently trying to create a workflow rule to close the tasks still opens of the lost leads.

I tried the workflowrule and update the field  but it does not work because they come from 2 different modules (task and lead).

So I tried to write a function that does not work also. Can you tell me what's wrong with that or anything else?

here the function,

if(status.contains("Junk"))
{
leadIdStr = leadId.toString();
relatedTask = zoho.crm.v1.getRelatedRecords("Tasks","Leads",leadIdStr);
for each  task in relatedTask
{
mapVariable = Map();
mapVariable.put("Status","Completed");
taskID = task.get("ACTIVITYID");
taskIdStr = taskID.toString();
updateTask = zoho.crm.v1.updateRecord("Tasks",taskIdStr,mapVariable);
}
}
if(status.contains("Junk"))
{
leadIdStr = leadId.toString();
relatedTask = zoho.crm.v1.getRelatedRecords("Tasks","Leads",leadIdStr);
for each  task in relatedTask
{
mapVariable = Map();
mapVariable.put("Status","Completed");
taskID = task.get("ACTIVITYID");
taskIdStr = taskID.toString();
updateTask = zoho.crm.v1.updateRecord("Tasks",taskIdStr,mapVariable);
}
}

Thank you

Kellian

1 user has this problem.
6 Replies
Reply
  • 5 years ago

Hey Kellian,

Thanks for trying to create the custom function on your own. Brownie points for trying! :)

Go to Setup -> Automation -> Actions -> Custom Functions -> Configure Custom Function -> Write your own ->
1) Choose module as 'Leads'
2) Give a custom function name of your choice
3) Copy and paste the code below

relatedTask = zoho.crm.getRelatedRecords("Tasks","Leads",leadId.toLong());
for each task in relatedTask
{
mapVariable = Map();
mapVariable.put("Status","Completed");
updateTask = zoho.crm.updateRecord("Tasks", task.get("id"),mapVariable);
info updateTask;
}

4) Click on 'edit arguments' (above the box where you pasted this code)
a) Choose Leads id (from drop down list) - name it as 'leadId' and save.
5) Click on Save and then we have to associate a workflow for the Leads module.

Setup --> Automation --> Workflow Rules --> + Create Rule --> Module Leads & rule name of your choice --> When? (on edit, I presume, since you'll be changing the status of the lead) Condition 1? (when lead status is lost lead) Instant Action? (the function you just created) --> Save.

Hope this helps.

Do keep testing it out and sharing your thoughts. Love to hear them.
Cheers!

Hello Andy,

Thank you very much for the function. I followed your steps and it works wonderfully for my lost leads.

I also need a function that would mark certain tasks completed when a Lead/Potential Status is changed. How could I do that, please?

Thank you very much for your time.

Cheers,
Sagat

Hi Marvin,

You can refer to the below sample code, this will close the junk lead tasks.

Arguments:
lead id and name it as leadId

if(status.contains("Junk"))
{
relatedTask = zoho.crm.getRelatedRecords("Tasks","Leads",leadId.toLong(),1);
for each task in relatedTask
{
mapVariable = Map();
mapVariable.put("Status","Completed");
updateTask = zoho.crm.updateRecord("Tasks",task.get("id"),mapVariable);
info updateTask;
}
}

Check and let us know if you have any further clarification.

Hi Andy, this worked thanks a mil

Also, what would the code look like if I wanted the same thing to happen in the deals module (I renamed the deals module to 'Job Cards'

Hello Warren,

If you can elaborate your use case here in detail and your requirement with the code you are using so we can check and help you with this.

Looking forward to hearing from you!

Reply to Andy NurseA
/* */
  • 12
  • Insert
  • Plain text
Add Comment
(Up to 20 MB )