Using queue functions to control dates and previously added items

Hi all

I’ve got to build a process which looks at emails from a shared inbox (can use the Outlook activities as robot has access to Outlook) and deal with emails which contain attachments - the robot gets the attachments and saves them to the required folders in a known location.

The business want the process to run every 30 mins during office hours (9am to 5pm)

I was originally going to load unread emails to a queue each time and work through them. However, the business have said they’d like the robot to look at all emails (in case a human has clicked on an email to make it ‘read’ but haven’t dealt with any attachments). The business has also said the robot can’t move any emails it has worked to a sub folder or delete them (‘humans’ will delete them as and when).

So i’m now struggling to work out how to add emails to the queue that haven’t been added before. I think I can use the ‘Get Queue’ function so I can check the queue for previously added items (as long as I give each email a unique reference value) but I don’t know how to control how far back the robot looks in the queue so this doesn’t become a long activity if there are 100’s of emails in the inbox.

I ideally need the robot, when adding items to the queue to look back around 18 hours when it’s been run for the first time that day (to account for any emails that have arrived overnight - but this would need to be longer on a Monday to account for the weekend) and then look back just 40 mins each time queue items are added for the rest of the day (as the process runs every 30 mins).

I would be really grateful for advice on how to do this please (including how to fill in the Get Queue activity/any assign stages with code that may be needed).

Thanks in advance