Variables in filename not typing (showing as "")


I am trying to save a PDF with the Name and DateTime details in a filename.

To do this I am saving an email into PDF and writing the filename with using the “Type into” activity but I am having some trouble writing the variable with the filename. It only seems to like fixed text. I am just trying to write the Date Time in the example below.

My Variable is being represented as “” when it is not actually blank (as supported by the write line activity).

My workflow looks like is taken from:
1. Within For Each Activity for Outlook emails

  • Str_DateTime = item.Headers(“Date”).ToString

2. Str_DateTimeCLEAN = System.Text.RegularExpressions.Regex.Replace(str_DateTime, “\/|:”, “-”)

  • Cleaning variable using Regex Replace method of any “\” or “:” and replacing them with “-” so its suitable for filename format.

3. Str_DateTimeCLEAN = 08-03-2020 14-24-44
Write line activity result: image

4. Type into activity is simply just treating the variable like its “”
Save as Result (screenshot):

  • image

Expression Editor: (added END for visual)

My Workflow Main.xaml (60.3 KB)

Its probably something simple that I have missed…

Any thoughts or assistance are always appreciated.

Thank you.

1 Like

Hi @Steven_McKeering,

Str_DateTimeFileName.Tostring and remove End.pdf string having some space before E

Omkar P

Hey @Reddy_Paluri

Updated folder structure to:
PDF\" + Str_DateTimeFileName + “.pdf”


No luck.

Hi @Reddy_Paluri

Updated folder structure with “.Tostring
"…\PDF" + Str_DateTimeFileName.ToString + “.pdf”

I am now getting this error message:
Main Sequence: Object reference not set to an instance of an object.

Please add the package:

Could you please try same process like you are doing .eml to pdf so try to save email as pdf those steps for manually by hand and check that time file name is coming or not

Still no luck.

I have tried updating the variable types to “UiPath.Generic” also but with no luck.

Hi @Reddy_Paluri

Thank you for your assistance.

I found TWO solutions.

Solution 1: I am adding an extra step where I use a “Move File” activity where I move the file back to the same location but with a new filename which is a working solution.

Its not my preferred method as I would prefer to type all in one step as less steps are better.

Solution 2: The “Type Into” activity appears to be working now BUT only when I choose a new folder…
So i have selected one folder further down called processed. I should be able to save to the same folder. This has resolved it.

The destination folder looks something like this:
PDF\Processed" + str_Name +" " + Str_DateTimeFileName + “.pdf”

Final Result in new folder:

Thank you



This works for me:

path+filename " + datetime.Now.ToString("MMddyyyy”) + “.pdf”

Thanks @bhicks11

But I need the date and time from the email not the system time when saving.

I hate Regex. This one item.Headers(“Date”) looks like a DateTime, but you will probably get it as an Object. You need simply to convert it into a DateTime first, then into a string with proper file-compatible format:
dReceived = CType(mail.Headers(“Date”).ToString , DateTime)
Str_DateTimeCLEAN =dReceived.ToString(“dd-MM-yyyy”)

Hello @RosenM

Good too see you back on the forums.

I am getting this error message when trying your solution.

Attaching demo project that does that, as well as (23.2 KB) shows all mail headers

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