Save csv file to shared folder using mid server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 10:48 AM
Hi,
I have been task with creating a csv in ServiceNow and saving it to a shared folder. I know that I can use the scheduled export, but that only allows me to save it to a file path relative to the Mid Server directory and also I need specific headers (which I will create through script). I want to use the mid server to save this file to that shared folder, but I am not sure how to go about that.
I am wondering if I should create a custom PowerShell to drop that file in that folder.
Does anyone have any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 03:09 PM
Hi @Dazler
You can configure the "Export Sets" for file transfer on MID Server path.
Create a Export Definition ( What data to export , you can select the columns)
Create a Export Target ( MID Server Name and Path configure )
Create a Export Sets ( configure the export definition & target here along with fileName & Format )
Refer my reply here :
Please mark helpful and correct answer if it helps
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 03:20 PM
Thank you for replying back but I can't use this because I needed special headers for my CSV that are not on the table. I can't use the table label for what i need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 03:42 AM
Hi ,
Did you get solution to place the file from mid server export folder to shared drive?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 07:04 AM
Hi @Sandhya V,
I created an action that passed inputs of the Attachment Sys id (attachment that will be saved) and Target Folder Path (where the file is being saved)
1st: set inputs on action
2nd: Set a script step to convert the csv to a GlideBase64 encoding
3rd: Set up a PowerShell that will take the encoded string and save it to the target folder path.
PowerShell script:
function Convert-StringToBinary {
[CmdletBinding()]
param (
[string] $EncodedString,
[string] $FilePath = ('{0}\{1}' -f $env:TEMP, [System.Guid]::NewGuid().ToString())
)
try {
if ($EncodedString.Length -ge 1) {
# decodes the base64 string
$ByteArray = [System.Convert]::FromBase64String($EncodedString);
[System.IO.File]::WriteAllBytes($FilePath, $ByteArray);
}
}
catch {
}
}
Convert-StringToBinary -EncodedString $Base64String -FilePath $TargetFileName
sleep 5
try{
Get-Item -Path $TargetFileName -ErrorAction Stop
Write-Output "File has been saved."
}
catch{
Write-Output "File was not saved | $($error[0].exception.message)"
}
Hopefully this will help.