I have created a table in an excel file, and the table has a customer column, date column, and date code column.
DateTime.Now.AddDays(-1*(7 + (DateTime.Now.DayOfWeek - DayOfWeek .Friday)) mod 7).Date.ToString(dd)
DateTime.Now.AddDays(-1*(7 + (DateTime.Now.DayOfWeek - DayOfWeek .Saturday)) mod 7).Date.ToString(dd)
The robot first reads the excel file, and then loops through the datatable.
I am trying to put the code from the Date code column to a field on a website so that I can get a date dynamically.
If CustA, put the previous Friday’s date . If CustB, put the previous Saturday’s date and so on.
I want to get a date like this:
But to access an item in the current row inside the loop, toString must be added to CurrentRow.Item("Date code") , and it makes the code a string, so doesnt work
I can put an if activity inside the loop to determine a date, but I’ll have to put all the possibilities e.g. if custA, use this code, if custB, use this code… I want to avoid enter each customer when a new one is added.
I want to make it versatile.
Is this literally what you have in that column of the spreadsheet? That’s not going to work. You can’t process an expression like that on the fly. You need to do that calculation in your UiPath code, not as the value in the spreadsheet.
Yes as my fellow community members tell you, you cant use the expression in excel and assume that the type into activity will input the result. You need to complete the logic of what you wrote in UiPath not excel.
DateTime.Now.AddDays(-1*(7 + (DateTime.Now.DayOfWeek - DayOfWeek .Monday)) mod 7).Date.ToString(“MM/dd/yyyy”)
shows the last Monday.
What I’m trying to do is that when the robot executes the process, it reads the excel file that has the table above. Then it loops the datatable and, inputs a date in a field. That date is provided by the expression and is depending on the customer.
I assume customer will be added in the future, and the date will defer by customer. That is why I want to use the excel file.
I want to achieve this without hardcoding to a robot.
It looks like the only difference in your expression is the DayOfWeek.day part. So create a variable to store it in, use a Switch based on the value of Date (ie Fri, Sat, etc) to populate the variable with the correct DayOfWeek value, then replace DayOfWeek.day with this variable.
That way the only thing you’re making a decision on is the Date (Fri, Sat, etc) and the rest of the expression doesn’t have to be repeated.