Attach Task Owner using Zoho Functions

Attach Task Owner using Zoho Functions

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
using API name according to API documentation
but also, there is no User module in it

zoho api
 #1 "Task Owner" field task created, but not attached
  1.    taskMap.put("Task Owner",task_owner);

// #2 "Owner" field name according to specification
// correct syntax according to help and doc
// => task is NOT created
  1. taskMap.put("Owner",task_owner);
// error: { 11// "code": "INVALID_DATA", 12// "details":{"api_name": "Owner"}, 13// "message": "invalid data", 14// "status": "error" 15// }

// #3 found that syntax usage in Zoho. help and previously created Zoho functions // => task created, not attached
  1. taskMap.put("SMOWNERID",task_owner);
also tried a nested structure
  1. taskMap.put("Task Owner",{"name": "user", "id":task_owner, "email":'user@org.com'});
and id types
  1. // 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 

2{"Owner":{ 5 "name": "System", 6 "id": "4228535000000298001", -- system user 7 "email": "zohocrm@positrace.com" 8 } 9 ... other task data 10}


Working on it in Sandbox

  1.  whole function

  2. // get it from params
  3. account_id = 2313923000257653114;
  4. opportunity_id = 2313923000259248184;
  5. // get all account opportunities
  6. account_opportunities = zoho.crm.getRelatedRecords("Deals","Accounts",account_id);
  7. account = zoho.crm.getRecordById("Accounts",account_id);
  8. // custom logic
  9. won_paid_counter = 0;
  10. // check opportunities stages
  11. for each  opportunity in account_opportunities
  12. {
  13. if(opportunity.get("Stage") == 'Won Paid')
  14. {
  15. won_paid_counter = won_paid_counter + 1;
  16. }
  17. }
  18. // if its only one won paid opportunity on account
  19. if(won_paid_counter == 1)
  20. {
  21. // get account_billing_country and found out future task owner
  22. account_billing_country = account.get('Account_Billig_Country');
  23. if(account_billing_country == 'Mexico')
  24. {
  25. task_owner = 2313923000216724001;  // 1User ID 
  26. }
  27. else
  28. {
  29. task_owner = 2313923000208553001;  // 2 User ID
  30. }
  31. // crate task
  32. taskMap = Map();
  33. taskMap.put("Subject",'NB Account to reassign to AM');
  34. taskMap.put("Due_Date",today.toDate().addDay(180));
  35. taskMap.put("Status",'not started');
  36. taskMap.put("Account",account_id);
  37. taskMap.put("$se_module","Deals");
  38. taskMap.put("What_Id",opportunity_id);
  39. taskMap.put("Task Owner",task_owner);
  40. taskMap.put("Description",'Zoho Automated Task');
  41. createResp = zoho.crm.createRecord("Tasks",taskMap);
  42. info taskMap;
  43. info createResp;
  44. info zoho.crm.getRecordById("Tasks",createResp.get('id'));
  45. }
  46. else
  47. {
  48.  info 'no task was created;
  49. }