Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Export csv to SFTP with headers only

Avatar

Level 2

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.

10 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

Avatar

Level 2

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.

Avatar

Level 2

@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

Avatar

Level 2

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 2

@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 2

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!