Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Tasks for other users using Exchange Web Services (EWS) Managed API

As an "EWS Managed API Newbie", I'm having some problems finding examples and documentation about creating and managing Tasks.

I've managed to create a task for myself without a problem. However, I really need to be able to do the following - if anyone could give me any pointers I'd really appreciate it...

  1. Create a Task and assign it to another user.
  2. Be able to interrogate the status of that task (percent complete, etc) whilst it is assigned to that user.
  3. Update the notes on the task at any time.

Thanks in advance for any pointers!

like image 477
Chris Roberts Avatar asked Jul 09 '10 00:07

Chris Roberts


2 Answers

The code in this post worked for me

Pasting code for posterity:

public string CreateTaskItem(string targetMailId)
    {

        string itemId = null;

        task.Subject = "Amit: sample task created from SDE and EWS";

        task.Body = new BodyType();

        task.Body.BodyType1 = BodyTypeType.Text;

        task.Body.Value = "Amit created task for you!";

        task.StartDate = DateTime.Now;

        task.StartDateSpecified = true;



        // Create the request to make a new task item.

        CreateItemType createItemRequest = new CreateItemType();

        createItemRequest.Items = new NonEmptyArrayOfAllItemsType();

        createItemRequest.Items.Items = new ItemType[1];

        createItemRequest.Items.Items[0] = task;

        /** code from create appointment **/

        DistinguishedFolderIdType defTasksFolder = new DistinguishedFolderIdType();

        defTasksFolder.Id = DistinguishedFolderIdNameType.tasks;
        defTasksFolder.Mailbox = new EmailAddressType();

        defTasksFolder.Mailbox.EmailAddress = targetMailId;

        TargetFolderIdType target = new TargetFolderIdType();

        target.Item = defTasksFolder;



        createItemRequest.SavedItemFolderId = target;


        try

        {

            // Send the request and get the response.

            CreateItemResponseType createItemResponse = _esb.CreateItem(createItemRequest);



            // Get the response messages.

            ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items;



            foreach (ResponseMessageType rmt in rmta)

            {

                ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items;

                ItemType[] items = itemArray.Items;


                // Get the item identifier and change key for each item.

                foreach (ItemType item in items)

                {


//the task id

                   Console.WriteLine("Item identifier: " + item.ItemId.Id);


//the change key for that task, would be used if you want to track changes ...
                    Console.WriteLine("Item change key: " + item.ItemId.ChangeKey);

                }

            }

        }

        catch (Exception e)

        {

            Console.WriteLine("Error Message: " + e.Message);

        }

        return itemId;

    }
like image 51
Chip McCormick Avatar answered Sep 18 '22 07:09

Chip McCormick


I've been taking a look into this, and i'm not sure it's possible using the Managed API.

I've got a system set up using four sample user folders, and a central admin user with delegated access to each of those user's mailboxes. When i attempt to find folders using the API, i can only find the folders of the user who's credentials i supply when creating the service object.

I'm also using the auto-generated proxy objects (only picked up the API to try and help), and I use the following process to create a task for another user (this works correctly...):

  1. Connect to the server as the central admin account.
  2. Create the task object as you would for your own account.
  3. Create a reference to the Tasks folder of the user that you want to send the item to.
  4. Create a CreateItemRequest object to pass to the server, and add the two items from steps 2 and 3 to the request

When the request is sent, the item is created in the target user's folder.

I was hoping that this sequence might be possible in the managed API, but it doesnt seem to work.

I'll keep working on it as i get the chance, but i have other issues with appointments that i'm working on as well. I figured the sequence might help anyone else looking, in case they have more luck.

Sorry i cant provide any more info at the moment

like image 39
LoneDeveloper Avatar answered Sep 19 '22 07:09

LoneDeveloper