"BC30451: 'currentItem' is not declared" inside For Each loop

Hello,

When trying to loop through email messages to get the date and content, I’m getting the error below:

‘VisualBasicValue’: Compiler error(s) encountered processing expression “currentItem.From”.(2) : error BC30451: ‘currentItem’ is not declared. It may be inaccessible due to its protection level.

“currentItem” is my Item Name in the For Each loop (i.e.: "For Each currentItem). I don’t have it declared anywhere else as a variable. I’m using UiPath Studio.

Any help would be appreciated.

1 Like

Post a screenshot of your For Each activity and its properties as well as the activity that is generating the error.

@tracylovett

Welcome to the community

  1. currentitem scope will be only inside for loop..outside it might not be accessible
  2. in latest for loop activities generally the name is dynamic based on the value you rpovide in input..for example for mails it generally will be currentmailitem..so better check the name properly ..in any field use ctrl+space to get the available values\

cheers

@tracylovett,

The item variable name get changed as per the datatype you are trying to iterate.

If you are iterating outlook mail messages, it would be most likely currentMailMessage

You can click on the For each activity and check property item name for exact name.

It was currentMailMessage by default, but I was getting the same error with that. I’m following a tutorial, so I changed it to match and I’m still getting the message with the new item name. I verified that the item name changed to match in the body of the For Each loop as well.

@tracylovett,

Ok, please share your project by zipping it. Let’s see what’s the issue.

Do I need to zip the entire project or just the xaml file?

@tracylovett,

Entire project would be good to have.

Looks like I haven’t been here long enough to upload anything. I’ll provide the zip file once I meet the upload requirements.

@tracylovett,

That’s difficult to debug. Try sharing the activities you are using and how it’s structured so we will get idea about your code.

It’s very basic so far. It’s the Working with App Integration activities page of the Email Automation With Studio section of the Automation Developer - Specialized AI Professional Training course here on UiPath.com. So far, it just gets emails that match an incident number then tries to pull the date and content and fill an audit log. It uses UiPath.Mail.Activities. I’m using the v2.1.0-preview build.

Hi @tracylovett

Replace currentItem.From with item.From or whatever your loop variable is.

Set TypeArgument to MailMessage.

Try this use message boxes for understanding