- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi Community,
I'm working on a ServiceNow integration use case and need some guidance.
Requirement:
Whenever a user uploads a file in the ServiceNow Attachment section, the same file should automatically be copied to a local Windows folder.
Example scenario:
- Windows Machine has a folder:
C:\ServiceNowLearning\
- User uploads a file in ServiceNow attachment section, for example:
employees.csv
- After upload, the same file should automatically appear in another local Windows folder such as:
C:\SN_Attachments\
Environment details:
- ServiceNow instance(PDI Zurich)
- Windows OS
- MID Server configured and running (Status = Up)
- Looking for a solution using MID Server / Business Rule / Flow Designer / PowerShell (any recommended approach).
Questions:
- What is the recommended approach for this scenario?
- Should this be implemented using Business Rule + ECC Queue + MID Server SystemCommand?
- Is Flow Designer + MID Server PowerShell capability a better/cleaner solution?
- How can the attachment binary/content be safely transferred from ServiceNow to the local Windows filesystem?
Note: When I'm running through the powersheel command manually, running then its showing in the local folder i created a poll_configure.ps1 file in the destination folder and command which i'm using is
powershell -ExecutionPolicy Bypass -File C:\ServiceNowAttachments\poll_attachments.ps1
If anyone has implemented a similar use case or has sample steps/scripts, it would be very helpful.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi @Rohitp484
To automatically copy an attachment uploaded in ServiceNow to a local Windows folder on a MID Server, you need to use a Business Rule that triggers an ECC Queue probe. This probe executes a PowerShell script on the MID Server to save the file.
Step 1: Create a MID Server Script Include
- Navigate to MID Server > Script Files in ServiceNow.
- Click New and set the Name (e.g., SaveAttachmentToFolder.ps1) and Parent to PowerShell.
- Add a PowerShell script that receives the file stream, converts the base64 content to bytes, and writes it to your local Windows directory.
Step 2: Create a Business Rule
- Navigate to System Definition > Business Rules and click New.
- Table: sys_attachment
- When: After
- Insert: Check the box
- Condition: table_name is your target table (e.g., incident, sc_req_item).
Sample script:
(function executeRule(current, previous /*null when async*/) {
if (current.table_name == 'your_custom_table' || current.table_name == 'incident') {
var targetFolderPath = 'C:\\ServiceNowLearning\\';
var agent = 'mid.server.YOUR_MID_SERVER_NAME';
var topic = 'Powershell';
var name = 'SaveAttachmentToFolder.ps1';
var payload = '<parameters>' +
'<parameter name="attachment_sys_id" value="' + current.sys_id + '"/>' +
'<parameter name="target_path" value="' + targetFolderPath + '"/>' +
'</parameters>';
var ecc = new GlideRecord('ecc_queue');
ecc.initialize();
ecc.agent = agent;
ecc.topic = topic;
ecc.name = name;
ecc.queue = 'output';
ecc.state = 'ready';
ecc.payload = payload;
ecc.insert();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
But I didn't get the business use-case for this requirement.
what purpose it serves?
User is uploading file from his/her local machine to ServiceNow, again why to copy that file to some other folder of that user?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi @Rohitp484
To automatically copy an attachment uploaded in ServiceNow to a local Windows folder on a MID Server, you need to use a Business Rule that triggers an ECC Queue probe. This probe executes a PowerShell script on the MID Server to save the file.
Step 1: Create a MID Server Script Include
- Navigate to MID Server > Script Files in ServiceNow.
- Click New and set the Name (e.g., SaveAttachmentToFolder.ps1) and Parent to PowerShell.
- Add a PowerShell script that receives the file stream, converts the base64 content to bytes, and writes it to your local Windows directory.
Step 2: Create a Business Rule
- Navigate to System Definition > Business Rules and click New.
- Table: sys_attachment
- When: After
- Insert: Check the box
- Condition: table_name is your target table (e.g., incident, sc_req_item).
Sample script:
(function executeRule(current, previous /*null when async*/) {
if (current.table_name == 'your_custom_table' || current.table_name == 'incident') {
var targetFolderPath = 'C:\\ServiceNowLearning\\';
var agent = 'mid.server.YOUR_MID_SERVER_NAME';
var topic = 'Powershell';
var name = 'SaveAttachmentToFolder.ps1';
var payload = '<parameters>' +
'<parameter name="attachment_sys_id" value="' + current.sys_id + '"/>' +
'<parameter name="target_path" value="' + targetFolderPath + '"/>' +
'</parameters>';
var ecc = new GlideRecord('ecc_queue');
ecc.initialize();
ecc.agent = agent;
ecc.topic = topic;
ecc.name = name;
ecc.queue = 'output';
ecc.state = 'ready';
ecc.payload = payload;
ecc.insert();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Could you please help where the mid server needs to be installed?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader