Remove quotes from CSV export set

Julie Gordon
Kilo Sage

I've seen similar posts, but haven't found an answer.

 

I have an Export Set that sends a .CSV file to our Mid Server.  Works beautifully.  But the requirement put upon me is to remove the double quotes(" ") from each field, so it ends up as a purely comma delimited CSV file.

 

Current file displays: "Julie", "Gordon", "Company"

Preferred file display: Julie, Gordon, Company

 

I'm thinking it has to be a pre-export script, but I'm newish to scripts & even newer to APIs.  Usually I can Frankenstein something together from prior posts, but would appreciate any help anyone can offer. 

1 ACCEPTED SOLUTION

Anvesh-  Thank you for your reply!  I had found that article, but it did send me down a different path.  Ultimately here's my solution.

1. Export Set to MID server

2. Symbolic link from MID server location to Network location(my requirement; also on my MID)

3. MID server script file as an attachment = powershell to take the CSV on the MID, remove quotes & replace.

4. Post Export Script on the Scheduled Export Set to trigger the powershell on the MID to run.

View solution in original post

5 REPLIES 5

AnveshKumar M
Tera Sage
Tera Sage

Hi @Julie Gordon 

You can use post script to modify the contents of file in mid server to your desired format.

 

Refer the following article where they change the file name, you can follow similar approach to replace the file content.

 

https://www.servicenow.com/community/developer-forum/change-file-name-in-mid-server/m-p/1718723#M375...

 

Thanks,
Anvesh

Anvesh-  Thank you for your reply!  I had found that article, but it did send me down a different path.  Ultimately here's my solution.

1. Export Set to MID server

2. Symbolic link from MID server location to Network location(my requirement; also on my MID)

3. MID server script file as an attachment = powershell to take the CSV on the MID, remove quotes & replace.

4. Post Export Script on the Scheduled Export Set to trigger the powershell on the MID to run.

Shubham47
Tera Expert

Hello Julie,

I also have a similar requirement, could you please help me with the script that you have used and steps to modify the header of csv file? 

On your Scheduled Data Export > Execute post-export script:

(function executeRule(current, previous /*null when async*/ ) {
  var ecc = new GlideRecord("ecc_queue");
  ecc.initialize();//to create record
  ecc.agent = "mid.server.MID SERVER NAME";
  ecc.topic = "Command";
  var value = "Powershell.exe C:\\LOCATION OF POWERSHELL SCRIPT ON YOUR MID SERVER";
  ecc.payload = '<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="name" value="'+value+'"/><parameter name="skip_sensor" value="true"/></parameters>';
  ecc.queue = "output";
  ecc.state = "ready";
  ecc.insert();
})(current, previous);
 
For the PS script on the mid, 
(Get-Content "CONTENT LOCATION PATH"). Replace (' " ', ' ') | Set-Content -Path CONTENT LOCATION PATH