Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards

Having while implementing this Javascript code in Adobe Campaign

Avatar

Level 1

// Variables
var FILE_PREFIX = "Mecca_Games_hashed_emails_";
var FILE_EXTENSION = ".csv";
var FILE_DIRECTORY = "C:\\Rank Sharing Folder\\MSAds\\";
// var SERVER_UPLOAD_URL = "https://duprdcpmgtstdstor01.blob.core.windows.net/msadsfiletransfer/"; // Replace with actual endpoint

// Generate timestamp and filename
var now = new Date();
var isoTimestamp = now.toISOString().replace(/:/g, "-");
var filenamePart = FILE_PREFIX + isoTimestamp + FILE_EXTENSION;
var filename = FILE_DIRECTORY + filenamePart;

// Query extracted data
var url = 'C:\\Rank Sharing Folder\\MSAds\\'; // Replace with your actual endpoint
var params = {
schema: vars.targetSchema,
operation: 'select',
select: ['@email']
};

fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(params)
})
.then(function(response) { return response.json(); })
.then(function(data) {
// handle your data here
console.log(data);
})
.catch(function(error) {
console.error('Error:', error);
});

var records = query.ExecuteQuery();

// Build CSV content
var CSV_HEADER = "EMAIL,\n";
var csvContent = CSV_HEADER;
for (var i = 0; i < records.length; i++) {
var record = records[i];
var email = record.email; // or record.@email.toString() in some environments
var hashedEmail = digestStrSha256(email);
csvContent += hashedEmail + "\n";
}

// Write to file
var file = new File(filename);
file.open("w");
file.write(csvContent);
file.close();
logInfo("File Written: " + filename);

// Send file to server (Node.js-style HTTP POST)
var uploadUrl = 'https://prodftp.rank.com'; // Use HTTPS for secure transfer
var fileInput = document.querySelector('input[type="file"]'); // Your file input element
var formData = new FormData();
formData.append('file', fileInput.files[0]); // 'file' is the form field name
var options = {
method: 'POST',
body: formData,
// Do NOT set Content-Type; the browser will set it to multipart/form-data with boundary
};
fetch(uploadUrl, options)
.then(function(response) { return response.json(); })
.then(function(data) {
// handle your response here
console.log(data);
})
.catch(function(error) {
console.error('Error:', error);
});

logInfo("File Written: \n" + filename);

kindly check why this is not working on Adobe Campaig 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies