I'm working on a custom function, that creates a Task and attached it to the user by id (through some custom logic)
planning to use that function in the workflow
But have an issue attaching newly created tasks to my user, task created but attached to the system user
tried to use 3 different syntax
but also, there is no User module in it
zoho api #1 "Task Owner" field task created, but not attached- taskMap.put("Task Owner",task_owner);
// #2 "Owner" field name according to specification
// correct syntax according to help and doc
// => task is NOT created
- taskMap.put("Owner",task_owner);
// error: {
// "code": "INVALID_DATA",
// "details":{"api_name": "Owner"},
// "message": "invalid data",
// "status": "error"
// }
// #3 found that syntax usage in Zoho. help and previously created Zoho functions
// => task created, not attached
- taskMap.put("SMOWNERID",task_owner);
also tried a nested structure
- taskMap.put("Task Owner",{"name": "user", "id":task_owner, "email":'user@org.com'});
and id types
- // task_owner = 2313923000216724001; --user id original (big num)
// task_owner = 2313923000216724001.toString() -- or user id string. same result
in creation success case got Task with nested "Owner" param
"Owner":{
"name": "System",
"id": "4228535000000298001", -- system user
"email": "zohocrm@positrace.com"
}
... other task data
}
Working on it in Sandbox
- whole function
- // get it from params
- account_id = 2313923000257653114;
- opportunity_id = 2313923000259248184;
- // get all account opportunities
- account_opportunities = zoho.crm.getRelatedRecords("Deals","Accounts",account_id);
- account = zoho.crm.getRecordById("Accounts",account_id);
- // custom logic
- won_paid_counter = 0;
- // check opportunities stages
- for each opportunity in account_opportunities
- {
- if(opportunity.get("Stage") == 'Won Paid')
- {
- won_paid_counter = won_paid_counter + 1;
- }
- }
- // if its only one won paid opportunity on account
- if(won_paid_counter == 1)
- {
- // get account_billing_country and found out future task owner
- account_billing_country = account.get('Account_Billig_Country');
- if(account_billing_country == 'Mexico')
- {
- task_owner = 2313923000216724001; // 1User ID
- }
- else
- {
- task_owner = 2313923000208553001; // 2 User ID
- }
- // crate task
- taskMap = Map();
- taskMap.put("Subject",'NB Account to reassign to AM');
- taskMap.put("Due_Date",today.toDate().addDay(180));
- taskMap.put("Status",'not started');
- taskMap.put("Account",account_id);
- taskMap.put("$se_module","Deals");
- taskMap.put("What_Id",opportunity_id);
- taskMap.put("Task Owner",task_owner);
- taskMap.put("Description",'Zoho Automated Task');
- createResp = zoho.crm.createRecord("Tasks",taskMap);
- info taskMap;
- info createResp;
- info zoho.crm.getRecordById("Tasks",createResp.get('id'));
- }
- else
- {
- info 'no task was created;
- }