Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

Export csv to SFTP with headers only

Avatar

Level 3

I have created a workflow where I'm extracting data and exporting the required column in csv format to SFTP location. But in case there are 0 records I have to export blank csv file to SFTP with headers only. 

 

Can you please guide how this can be achieved. Currently it creates blank file without headers.

 

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 3

Achieved using Javascript activity.

 

var f = new File(vars.filename)
f.open("a"); //append mode
f.writeln("column_name1,column_name2,column_name3");
f.close()

 

 

 

View solution in original post

11 Replies

Avatar

Community Advisor

Hello @parmeshwarr3905 ,

you can create file with and write headers in to it when there is no records from JS activity. Or you can create one dummy file with headers save it to the server file storage and send that instead when there is no data.

 

Marcel

Hi @Marcel_Szimonisz 

 

I have used test activity to check if there are zero records then next is JS activity where i'm writing a code to create a file with headers but i'm getting an error "Access to file '<path>' is forbidden "

 

parmeshwarr3905_1-1650888032432.png

 

 

 

please let me know the error reason or alternate way.

I can create a dummy file as you suggested but if someone deletes that by mistake it could be a problem.

@Marcel_Szimonisz if there is already a solution based on javascript code could you please point me to that? I'm not able to troubleshoot this further

Avatar

Community Advisor

where did you put the blank file? add it where all files are exported so you can access it..

 

nl6/var/[YOUR_INSTANCE_NAME]/export

Marcel

I have placed my file on sftp location

sftp://<instance>/incoming/export/

 

Can I move it to different folder from that location say 

sftp://<instance>/incoming/export/integration/

 

Thanks,

Parmeshwar

Avatar

Employee Advisor

HI there,

Why use a Java Script when the Data Extract activity is already proposing the capability

Denis_Bozonnet_0-1651155418937.png

If there is no record, a file with just the header will be created, no need to JavaScript.

Let me know if it solves your topic,

Thanks
Denis

 

Avatar

Level 3

@Denis_Bozonnet  I had that option selected but it is creating a file without headers. correct me if I'm missing any other settings

 

parmeshwarr3905_0-1651156313480.png

Thanks

Avatar

Employee Advisor

Hi, this is new then because it has worked in the past for sure....sorry to hear it doesn't anymore... back to the JS which isn't great really....

Thanks

Denis

Avatar

Level 3

Hi @Denis_Bozonnet Yes right, could you help me out on setting up JS activity?

 

Thanks,

Parmeshwar

Avatar

Employee Advisor

Hello @parmeshwarr3905 
Please see below setup
Test activity -> To check for 0 Records
Query activity -> To fetch 1 record from any schema. Maybe use a Primary Key filter from nms:recipient or any other schema.
Data extraction activity -> 
- uncheck Use first line as column header
- Data formatting step, provide the number of header columns with
Create new of Type Fixed String

Provide your header string in the edit box without any single/double quotes

Kishore_Padamata_0-1653051797608.gif

Hope this helps!

Avatar

Correct answer by
Level 3

Achieved using Javascript activity.

 

var f = new File(vars.filename)
f.open("a"); //append mode
f.writeln("column_name1,column_name2,column_name3");
f.close()