IF Condition Help

Hi Friends,

I get the following error in the if activity. How can I solve it?

I want to print 202502 while in period 202503. When in period 202501 it should say 202412.

Thank you for your support and cooperation.

Something went wrong with .
Activity If (If) failed:

Expression Activity type ‘VisualBasicValue`1’ requires compilation in order to run. Please ensure that the workflow has been compiled.

You can find the activity by searching id (press Ctrl + J to jump to activity):
0101F

Hey @ozgur.yukcan
You can simplify the expression without using <[ ]>. Just switch to expression mode in the Text field and use:

Now.AddYears(-1).ToString("yyyy") + Now.AddMonths(-1).ToString("MM")

This works directly in the Type Into activity. The <[ ]> syntax is only needed in pure Text Builder mode, which is not required here.

You can also move the logic into a separate Assign activity using a string variable and use it in type into activity.

Hi,

If you want to type the previous month’s year and month, it’s unnecessary to use IF activity and the following will work.

Now.AddMonths(-1).ToString("yyyyMM")

Regards,

Hi @ozgur.yukcan

If you need a simple solution, use Now.AddYears(-1).ToString("yyyy") + Now.AddMonths(-1).ToString("MM") directly in the Type Into activity.

If you want better readability and debugging, assign previousPeriod = If(Now.Month = 1, Now.AddYears(-1).ToString("yyyy") + "12", Now.ToString("yyyy") + (Now.Month - 1).ToString("00")) in an Assign activity and use the variable in the Type Into activity. If you face a compilation error, the Assign method is more stable.

If you found helpful mark as solution.
Happy Automation with UiPath

PreviousMonth.zip (84.0 KB)
AddMonth() function can automatically take care of going to previous year, if the month is January. No need to explicitly use any if condition to achieve that.
I have attached a code snippet, please refer.

@ozgur.yukcan

To achive the output - we dont need to use any if activities. Below simple expression would do

Datetime.now.AddMonths(-1).ToString(“yyyyMM”)

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