How to get agenda events from Outlook

outlook

#1

Hi everyone,

I would like to know if there is any way to get an event (as there is no activity related to it) from the Outlook Agenda with Ui Path ? Except by doing it manually with the robot (i.e. open Outlook, go to Agenda, and select an Event).

Thanks for your answers,

Enzo


#2

I don’t think UiPath has it and I’m not sure if it could be accomplished by Invokemethod activity.

May be you can create your own custom activity using below code?

https://msdn.microsoft.com/en-us/library/office/gg619398.aspx

For custom Activity


#3

Thanks for your help!

I managed to do so, unfortunately it throws an error when I run the XAML File in Ui Path.

Do you have any idea of where it can come from ? Searched on Google but none of the answers provided helped in my case.

Here is the error :

Main has thrown an exception

Message: Cannot create unknown type '{clr-namespace:NameSpaceOutlook;assembly=ActivitiesOutlookAgenda}OutlookAgendaActivitiesClass'.

Source: System.Xaml

Exception Type: XamlObjectWriterException

System.Xaml.XamlObjectWriterException: Cannot create unknown type '{clr-namespace:NameSpaceOutlook;assembly=ActivitiesOutlookAgenda}OutlookAgendaActivitiesClass'.
   at System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
   at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
   at System.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)
   at System.Activities.XamlIntegration.FuncFactory`1.Evaluate()
   at System.Activities.DynamicActivity.OnInternalCacheMetadata(Boolean createEmptyBindings)
   at System.Activities.Activity.InternalCacheMetadata(Boolean createEmptyBindings, IList`1& validationErrors)
   at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack`1& activitiesRemaining, ActivityCallStack parentChain, IList`1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback)
   at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList`1& validationErrors)
   at System.Activities.ActivityUtilities.CacheRootMetadata(Activity activity, LocationReferenceEnvironment hostEnvironment, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList`1& validationErrors)
   at System.Activities.Hosting.WorkflowInstance.ValidateWorkflow(WorkflowInstanceExtensionManager extensionManager)
   at System.Activities.Hosting.WorkflowInstance.RegisterExtensionManager(WorkflowInstanceExtensionManager extensionManager)
   at System.Activities.WorkflowApplication.EnsureInitialized()
   at System.Activities.WorkflowApplication.Enqueue(InstanceOperation operation, Boolean push)
   at System.Activities.WorkflowApplication.SimpleOperationAsyncResult.Run(TimeSpan timeout)
   at System.Activities.WorkflowApplication.BeginRun(AsyncCallback callback, Object state)
   at UiPath.Executor.RobotRunner.<>c__DisplayClass49_0.<OnInvokeJob>b__0()

#4

Did you create and install the Nuget Package? Can you share your custom code here?


#5

Yes I can drag and drop my custom activity in Ui Path. It’s just throwing me this error when I try to use it.

Here is my code.

Again, thank you very much for your help.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using System.ComponentModel;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
using System.Diagnostics;
using System.Activities.Presentation.Metadata;



namespace NameSpaceOutlook
{

    public class OutlookAgendaActivitiesClass : CodeActivity
    {
        [Category("Input")]
        [RequiredArgument]
        public InArgument<String> TodayDate { get; set; }

        [Category("Output")]
        public OutArgument<Array> Appointments { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            var DateString = TodayDate.Get(context);
            var Date = DateTime.ParseExact(DateString, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            var rangeAppts = new Outlook.Items();

            Outlook.Application OutlookApplication = new Outlook.Application();
            Outlook.Folder calFolder =
                OutlookApplication.Session.GetDefaultFolder(
                Outlook.OlDefaultFolders.olFolderCalendar)
                as Outlook.Folder;
            DateTime start = Date;
            DateTime end = start.AddDays(3);


            string filter = "[Start] >= '"
                + start.ToString("g")
                + "' AND [End] <= '"
                + end.ToString("g") + "'";
            Debug.WriteLine(filter);
            try
            {
                Outlook.Items calItems = calFolder.Items;
                calItems.IncludeRecurrences = true;
                calItems.Sort("[Start]", Type.Missing);
                Outlook.Items restrictItems = calItems.Restrict(filter);
                if (restrictItems.Count > 0)
                {
                    rangeAppts = restrictItems;
                }
                else
                {
                    rangeAppts = null;
                }
            }
            catch { rangeAppts = null; }

            if (rangeAppts != null)
            {
                foreach (Outlook.AppointmentItem appt in rangeAppts)
                {
                    Debug.WriteLine("Subject: " + appt.Subject
                        + " Start: " + appt.Start.ToString("g"));
                    Appointments.Set(context, appt.Subject);
                }
            }
        }
    }
}

#6

I will take a look into it, I may not be sure about this, but do you have any dll that needs to be registered in GAC

@andrzej.kniola might have an answer


#7

Hum well I have absolutely no idea :neutral_face:
What could possibly go wrong with the GAC?

Thanks for your help anyway

Edit : I added my .dll file to the GAC. Still throws the same error.


#8

Not exactly sure @EnzoH. May be something inside Uipath.

Can you check if you have the below installed?


#9

No I have not. I try right now.

Edit : Does not fix the issue


#10

Can you send the nuget package?


#11

Here it is : https://we.tl/YUfHTnzxY3


#12

Cannot open the link, can you just upload the nuget?

Edit: @EnzoH never mind i was able to create nuget with your code and I get a different error when i enter the date and execute the code. Something to do with the code itself.


#13

Try this code, works for me in visual studio.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using System.ComponentModel;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Diagnostics;
using System.Activities.Core.Presentation;



namespace NameSpaceOutlook
{

    public class OutlookAgendaActivitiesClass : CodeActivity
    {
        [Category("Input")]
        [RequiredArgument]
        public InArgument<String> InputDate { get; set; }

        [Category("Output")]
        public OutArgument<Array> Appointments { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            Microsoft.Office.Interop.Outlook.Application oApp = null;
            Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
            Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

            oApp = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace = oApp.GetNamespace("MAPI");
            DateTime start = DateTime.Parse(InputDate.ToString());
            DateTime end = start.AddDays(3);
            string filter = "[Start] >= '"
                + start.ToString("g")
                + "' AND [End] <= '"
                + end.ToString("g") + "'";
            CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar); outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.IncludeRecurrences = true;
            outlookCalendarItems.Sort("[Start]", Type.Missing);
            Outlook.Items restrictItems = outlookCalendarItems.Restrict(filter);
            int count = outlookCalendarItems.Count;
            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem appt in restrictItems)
            {

                Debug.WriteLine("Subject: " + appt.Subject
                        + " Start: " + appt.Start.ToString("g"));
                Appointments.Set(context, appt.Subject);
            }
        }
    }
}

#14

Hi vvaidya, thanks for helping me.

Unfortunately I always get the same error even with your code.
I tried with another computer, still the same.

So if it works with your environment I guess the error does not come from the code but from other parameters maybe in the package creation or his interpretation by Ui Path.

Maybe you can send me your nuget package so I can try it. (I could not attach files to my post as I am a new user, that’s why I used WeTransfer previously).

Again, thank you for your time.