cancel
Showing results for 
Search instead for 
Did you mean: 

Process starts on placing a file inside a certain location

RajnishPandey
Level 2
Hi Everyone,

I have a question I want to ask to the community.
We have a business requirement where the developed process should start when an excel file is placed inside a folder in SharePoint. Currently I am using the logic of scheduling the process once a day and at the start of the process checking if an excel file exist in the location, if yes the bot will move ahead otherwise will end the process there.

If anyone from the community has any suggestion of achieving the business requirement please guide me.

------------------------------
Thanks and Regards
Rajnish Pandey
------------------------------
Thanks and Regards [FirstName] [LastName] [Designation] [JobTitle] [CompanyName] [City] [State] [Phone]
6 REPLIES 6

ewilson
Staff
Staff
Hi @RajnishPandey,

If you're experienced in developing Windows services or even just a regular console application in .NET, which could be scheduled under the Windows scheduler, you could write a small application that monitors the folder w/o tying up a BP license until it's actually needed. If you go the Windows service route you could monitor the folder continually using the FileSystemWatcher class of .NET and then launch the necessary BP process from using AutomateC when the new file is created.

UPDATE: I forgot that a developer on my team actually created a standard service for this functionality. You can find it on the Digital Exchange at the following link. Download it, give it a go, and let us know what you think.

https://digitalexchange.blueprism.com/dx/entry/9648/solution/file-watcher-service-integration

Cheers,


------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Hi @ewilson,

Thank you for the solution, I will try it and let you know if this fix would work for our process.



------------------------------
Rajnish Pandey
------------------------------
Thanks and Regards [FirstName] [LastName] [Designation] [JobTitle] [CompanyName] [City] [State] [Phone]

Does it work?



------------------------------
Christoph Komorovski
Digital Solution Architect
Mercedes-Benz AG
Stuttgart
------------------------------

somehow the config is wrong during installation. It referes to an xml file on drive d which doenst exist. 



------------------------------
Christoph Komorovski
Digital Solution Architect
Mercedes-Benz AG
Stuttgart
------------------------------

Hi Eric,

In the original thread for this question others found this tool from the DX did not work.  We tried it also in January 2024 and found the same.

Has this been fixed please?  I see no changes on the relevant DX page.

Is there an alternative method or tool for file watching

Thank you and regards

Darren Rundell

RPA Developer - Royal Cornwall Hospitals Trust - UK

Hi @DarrenRundell ,

I can suggest you an alternative way which would be to use a simple python script that can keep on checking if any file got placed within a folder or not. If yes, it can trigger a process using the AutomateC.exe file. Once this script has been created, you can execute the same using Windows Scheduler at some interval (for example, every 15 minutes)

Python Script:

import os
import subprocess
import json
import logging
from datetime import datetime

# Configuration
WATCH_FOLDER = r"<WATCH_FOLDER>"
AUTOMATEC_PATH = r"C:\Program Files\Blue Prism Limited\Blue Prism Automate\AutomateC.exe"
USERNAME = "<USER_NAME>"
PASSWORD = "<PASSWORD>"
PROCESS_NAME = "<PROCESS_NAME>"
RECORD_FILE = "processed_files.json"
LOG_FILE = r"C:\temp\watch_folder_trigger_bot.log"

# Setup logging
logging.basicConfig(
    filename=LOG_FILE,
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S'
)

def run_blue_prism_process():
    try:
        command = [
            AUTOMATEC_PATH,
            "/user", USERNAME, PASSWORD,
            "/run", PROCESS_NAME
        ]
        result = subprocess.run(command, capture_output=True, text=True)
        if result.returncode == 0:
            logging.info("Blue Prism process triggered successfully.")
        else:
            logging.error(f"Failed to trigger Blue Prism process. Error: {result.stdout}")
    except Exception as e:
        logging.error(f"An error occurred while triggering the Blue Prism process: {e}")

def load_processed_files():
    if os.path.exists(RECORD_FILE):
        with open(RECORD_FILE, "r") as file:
            return set(json.load(file))
    else:
        return set()

def save_processed_files(processed_files):
    with open(RECORD_FILE, "w") as file:
        json.dump(list(processed_files), file)

def watch_folder():
    processed_files = load_processed_files()
    
    current_files = set(f for f in os.listdir(WATCH_FOLDER) if os.path.isfile(os.path.join(WATCH_FOLDER, f)))
    new_files = current_files - processed_files
    
    if new_files:
        logging.info(f"New file(s) detected: {new_files}")
        run_blue_prism_process()
        processed_files.update(new_files)
        save_processed_files(processed_files)
    else:
        logging.info("No new files detected.")

if __name__ == "__main__":
    logging.info("Starting folder watch...")
    watch_folder()

Here, you need to replace the Username, Password, Process Name and the Watch folder variable values with values specific to your use case.

What this script does is that it will check if there is any new file within your watch folder. If yes, it will check in a JSON file that it creates and tracks for the processed file otherwise will stop the process. If the entry is not found, then it will add the record entry with the file name and will trigger the process via AutomateC.exe application otherwise will stop the process.

Once the script has been created, save the python file in some directory and we will create the schedule in Task Scheduler and click on Create Task option from the Actions panel:

devneetmohanty07_1-1719702167758.png

 

Provide the task name, description and select the options: Run whether user is logged on or not and Run with highest privileges and select the Operating System:

devneetmohanty07_3-1719702747599.png

 

Now, click on Triggers tab at top and provide the Trigger to be at startup and repeat every 5 minutes indefinitely as shown below:

devneetmohanty07_4-1719703017028.png

 

Now, set up the actions to trigger the python script using the python.exe file path and run the script in the same directory path where the script file is saved:

devneetmohanty07_5-1719703087868.png

 

Once it has been setup, in the task scheduler your task should show up and now it should work.

---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.