Use Code in UiPath

Hi,

Is there a way to use the following code in my solution?

using System;
using System.Linq;

namespace Shawn2
{
class Program
{
static void Main(string args)
{
geDateForShawn();
}

    private static void geDateForShawn()
    {
        var outputDate = "";
        string date = DateTime.Now.ToString("dd/MM/yy");

        DateTime enteredDate = DateTime.Parse(date);
        DateTime nextMonth = new DateTime(enteredDate.AddMonths(1).Year, enteredDate.AddMonths(1).Month, 1);

        int daysInMonth = DateTime.DaysInMonth(enteredDate.Year, enteredDate.Month);

        var workingDaysRemaining = WorkDaysInMonthEnum(enteredDate);

        if (workingDaysRemaining.Count() <= 3)
        {
            var workingDayDates = WorkDaysInMonthEnum(nextMonth);
            var thirdDay = workingDayDates[2];
            outputDate = ("" + thirdDay.Day + "/" + enteredDate.AddMonths(1).Month + "/" + enteredDate.AddMonths(1).Year);
        }
        else
        {
            outputDate = ("" + daysInMonth + "/" + enteredDate.Month + "/" + enteredDate.Year);
        }
    }

    public static DateTime[] WorkDaysInMonthEnum(DateTime currentDate)
    {
        var remainingDates = Enumerable.Range(currentDate.Day, DateTime.DaysInMonth(currentDate.Year, currentDate.Month) - currentDate.Day + 1)
                            .Select(day => new DateTime(currentDate.Year, currentDate.Month, day))
                            .Where(day => day.DayOfWeek != DayOfWeek.Sunday && day.DayOfWeek != DayOfWeek.Saturday);

        return (remainingDates.ToArray());
    }
}

}

Regards,
Shawn

@shawnmurray

You can use Invoke Code activity.

1 Like

Can this be used with c# code or is it only VB.net?

Regards,
Shawn

@shawnmurray Try to use Invoke code activity.

1 Like

You can select VBnet or CSharp in the Language property of Invoke Code.
There is also an Invoke VBA activity.

Cheers, Lukas

1 Like

thanks @lukasziebold

See attached.
Test.xaml (6.0 KB)

Sure thing :wink:

Test.xaml (3.9 KB)

Don’t forget to update your packages!

Cheers, Lukas

1 Like

Hi @lukasziebold ,

The invoke code method is empty, i must of done something wrong?

Regards,
Shawn

When I opened your workflow file, there was only a corrupted activity.

I only added the activity to the workflow, I didn’t insert your code. You can go ahead and Edit it yourself :slight_smile:

Cheers, Lukas

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.