Copy each File name from saved attachement

okay it’s getting the staffnumber.pdf in the output field but I don’t want the file extension.

The error message": "Write Line: Index was outside the bounds of the array only appears when I have filename(1) in the write line activity.

Sorry for all the questions @chandu4712

No problem @scotthutton :smile: questions is how we will solve it.

If you are getting an output something like 1234567.pdf
And you are sure that your staffnumber will only be in digits.

Use below expression in Write Line Activity to get only digits out of string.
System.Text.RegularExpressions.Regex.Replace(filename(1),"\D","")

1 Like

Perfect that worked a treat, but still getting that same error.

Source: Write Line

Message: Index was outside the bounds of the array.

Exception Type: System.IndexOutOfRangeException

@scotthutton
You are splitting the file name and accessing filename(1). But before this you need to check the array(filename) length is greater than 1.
If the array contains only one item, then you should access the element in the 0th index.
i.e., if(filename.Length > 0)
In write line use filename(0)

Hope this resolves your problem.

2 Likes

@Madhavi Do i even need to split the file name if I only want to copy part of it?

@scotthutton Can you specify one of your file names and what you are trying to retrieve from the file name?

@Madhavi file name is TEXT-1234567.pdf, all I want is to copy the number for each file that get’s saved into a folder and search for that number in an excel sheet, then I want to copy text from the excel sheet and paste in as a password to a PDF file

Use regex,

  1. Use IsMatch activity to check is there any number exists in the filename. Please set the properties as specified below Capture
  2. Add if activity to check the output of IsMatch activity.
  3. If output is false, there is no number exists in the file name and so capture it as exception. Else if output is true, use Matches activity and set the property as specified below
    Capture
  4. Now to get the number value from Matches activity as specified below
    Capture

Hope this helps!

1 Like

@Madhavi would you mind putting that on a workflow, I am getting all kinds of errors and want to check I am doing it correctly.

@scotthutton
Please send your workflow. i will review once

If.xaml (10.7 KB)
@Madhavi attached workflow.

@scotthutton

Please find the below workflow GetNumberFromFileName.xaml (17.7 KB)

Hope this is helpful!

1 Like

@Madhavi this is great and works as it should do. 1 question, the result in the output I want to copy the specific number each time and run that through a loop to then do a further process. I can’t find a way to copy that field and search for it in a excel sheet.

Instead of writing into logs, add the value to an array or list. later you can loop through that and do further processing.

@Madhavi thanks for this, I will give it a try.

Hi @Madhavi I am just not getting this. I’ve tried adding the value (unique number) to a list and still it outputs to the output field.

Can you please send me your workflow. I will check it once.

Each number in the output field still shows, I’ve reverted back to my original workflow. I think the log message activity needs to be removed and a different activity added to get the data to excel

@Madhavi I’ve managed to write the output to a .txt file but it’s giving me the path and only 1 entry, I have 12 file names.

any ideas?

@scotthutton
I really need to look through the source code. unable to predict any solutions at this moment.
If you dont want to share your source code, send the screenshot where you are adding the entry to output file.
One reason I could think of is, you might be overwritting the .txt file. Recheck this.