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.
Solved! Go to Solution.
Views
Replies
Total Likes
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()
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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 "
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.
Views
Replies
Total Likes
@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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
HI there,
Why use a Java Script when the Data Extract activity is already proposing the capability
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
Views
Replies
Total Likes
@Denis_Bozonnet I had that option selected but it is creating a file without headers. correct me if I'm missing any other settings
Thanks
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Replies
Total Likes
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
Hope this helps!
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()
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies