Reassigning all tasks from one user to another
Sometimes you may need to reassign all the tasks from one user to another, for example, when dismissing an employee. This article provides an example of a script which reassigns multiple tasks. Before executing the script, you need to unlock the account of the dismissed employee.
var zdch=InterfaceActivator.Create<TaskBaseFilter>(); //create a task filter
zdch.Executor=context.User; //find the user's task
var spzdch=TaskBaseManager.Instance.Find(zdch,null); //create a list of user tasks
spzdch.ForEach(odzdch=>odzdch.Executor=context.Usernew);// assign the tasks to the new user
Documentation on PublicAPI is available here
var tasks = PublicAPI.Portal.TaskBase.Filter().Executor(context.User).Find(); //create the list of user tasks
foreach (var task in tasks)
task.Executor = context.Usernew; // assign the tasks to the new user
One execution of this script is enough. Either in the emulation mode without rollback or in a business process.
This way you can reassign only user tasks created in the web part. For this, use TaskFilter and TaskManager, or for leads use LeadFilter and LeadManager.