Hi there,
"I am passing the recipient's email through a survey URL generated in Adobe Campaign and need to decrypt this email address. I'm using a JavaScript function to extract the email parameter from the URL, decrypt it, and send the data to a table. However, the decrypted string is still appearing as an encrypted string for some reason."
?email_id=<%= escapeUrl(cryptString(targetData.email)) %>
function decryptString(encryptedEmail) {
// Implement your decryption logic here
return encryptedEmail; // Placeholder: returning the input as-is
}
// Function to decrypt and extract the email address from the URL
function getEmailFromUrl() {
const params = new URLSearchParams(window.location.search);
const encryptedEmail = params.get('email_id');
// Decrypt the email address using the decryptString function
const email = decryptString(encryptedEmail);
return email;
}
// Function to validate the survey, set values, and submit the form
function validate() {
// Get the email address from the URL
const email = getEmailFromUrl();
if (!email) {
alert("Error: Email address is missing.");
return false;
}
if (isValid) {
// Set the email address to the "Email_Address" path
document.controller.setValue("/ctx/FOD_SurveyResponse/@Email_Address", email);
// Submit the form if validation passed
document.controller.submit('next', '_self', 'next');
}
return isValid;
}
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @_Manoj_Kumar_ ,
Thank you for your assistance. The code below successfully enabled me to decrypt the email string and store it in the corresponding schema column.
.
ctx.vars.key256Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc";
ctx.vars.Email_Address = ctx.vars.Email_Address.toString();
ctx.FOD_SurveyResponse.@Email_Address = decryptString(ctx.vars.Email_Address, ctx.vars.key256Bytes);
Views
Replies
Total Likes
Hello @rvnth This is because you have created a function with similar name it is not doing anything.
remove this code:
function decryptString(encryptedEmail) {
// Implement your decryption logic here
return encryptedEmail; // Placeholder: returning the input as-is
}
Also, I would suggest you to some other identifier than email
Hi @_Manoj_Kumar_ ,
Thank you for your response. After removing decryptString, I'm encountering an error stating that decryptString is not defined in the code block below. Since the Adobe decryptString function isn't working here, is there an alternative way to decrypt?
function getEmailFromUrl() {
const params = new URLSearchParams(window.location.search);
const encryptedEmail = params.get('email_id');
// Decrypt the email address using the decryptString function
const email = decryptString(encryptedEmail);
return email;
}
Thank you in advance.
Is it possible to decrypt this directly at the attribute level within the Schema, or do I need to send only the decrypted string data?
Views
Replies
Total Likes
Hello @rvnth You have to use this on server side and it won't work on client side.
Here is what you should to
Thank you for your response. Can I use a JavaScript activity within the survey application to apply the decryptString function? Additionally, if I include the survey URL in an email as a batch, can I process each email address individually using a loop? I’m still figuring out how to track which customer has submitted the response. I have created a custom schema to store survey responses, which includes fields such as question1, question2, question3, VIN, email_id, and email_address. This schema is linked with the recipient table (email_id) and the vehicle table (VIN).
Views
Replies
Total Likes
Hi @_Manoj_Kumar_ ,
I attempted to use the JavaScript code below within the JS activity but encountered an error:
// Function to get parameters from the URL
function getParameterFromUrl(param) {
var params = new URLSearchParams(window.location.search);
return params.get(param);
}
// Function to set decrypted values from URL parameters
function setValuesFromUrl() {
// Get encrypted VIN and email ID from the URL
var encryptedEmailId = getParameterFromUrl('email_id');
// Decrypt values using the decryptString function
var decryptedEmailId = '';
if (encryptedEmailId) {
decryptedEmailId = decryptString(encryptedEmailId);
console.log("Decrypted Email ID:", decryptedEmailId); // Debugging log
}
// Set the decrypted values in the survey response context
if (typeof document.controller !== 'undefined') {
document.controller.setValue('/ctx/FOD_SurveyResponse/@Email_ID', decryptedEmailId);
} else {
console.error("document.controller is not defined.");
}
}
// Function to validate the survey, set values, and submit the form
function validate() {
// Define the questions and their corresponding names
var questions = [
{ name: "Question1", errorMessage: "Please select at least one option for Question1." },
{ name: "Question2", errorMessage: "Please select at least one option for Question2." },
{ name: "Question3", errorMessage: "Please select at least one option for Question3." },
// Add more questions as needed
];
// Flag to determine if validation passed
var isValid = true;
// Loop through each question
questions.forEach(function(question) {
var questionInputs = document.querySelectorAll('input[name="' + question.name + '"]');
var selectedAnswers = document.querySelectorAll('input[name="' + question.name + '"]:checked');
if (questionInputs.length > 0) { // Check if the question exists on the page
if (selectedAnswers.length === 0) {
// If no options are selected, show alert and focus on the first input
alert(question.errorMessage);
questionInputs[0].focus();
isValid = false; // Set validation flag to false
} else {
// Set values for each selected answer in the controller
selectedAnswers.forEach(function(answer) {
if (answer.type === 'checkbox') {
document.controller.setValue('/ctx/FOD_SurveyResponse/@' + question.name, answer.value);
}
});
}
}
});
// Set values from the URL before submission
if (isValid) {
setValuesFromUrl();
// Submit the form if validation passed
if (typeof document.controller !== 'undefined') {
document.controller.submit('next', '_self', 'next');
} else {
console.error("document.controller is not defined.");
}
}
return isValid;
}
// Call validate function on form submission
document.querySelector('form').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent default form submission
validate(); // Call the custom validation function
});
Please suggest
Thank you in advance.
Views
Replies
Total Likes
Also, share the screenshot of the webapp with activities used and highlight the activity where this code is used.
Views
Replies
Total Likes
Hi @_Manoj_Kumar_ ,
I’m still working on this myself but am having trouble understanding a few things. I’ve outlined them below, and I’d appreciate your help:
When should we use /ctx/vars/variable_name?
I’ve declared a few variables in the properties section of a WebApp and am using those in the URL to dynamically render the form.
I’m trying to access the first parameter in the URL, which I’ve encrypted using a 256-bit key. I’ve successfully accessed the encrypted string using the function below:
function getEmailFromUrl() {
var params = new URLSearchParams(window.location.search);
var encodedEmailId = params.get('email_id');
if (!encodedEmailId) {
return null; // No email_id found
}
// Decode the URL-encoded string
var decodedEmailId = decodeURIComponent(encodedEmailId);
// Replace special URL-encoded characters with their original values
decodedEmailId = decodedEmailId.replace(/%2B/g, '+')
.replace(/%2C/g, ',')
.replace(/%2F/g, '/')
.replace(/%3A/g, ':')
.replace(/%2D/g, '-')
.replace(/%3B/g, ';')
.replace(/%2E/g, '.')
.replace(/%40/g, '@') // Keep @ decoding
.replace(/%3D/g, '=');
// Remove the leading '@' and trailing '=' if present
if (decodedEmailId.startsWith('@')) {
decodedEmailId = decodedEmailId.slice(1); // Remove leading '@'
}
if (decodedEmailId.endsWith('=')) {
decodedEmailId = decodedEmailId.slice(0, -1); // Remove trailing '='
}
// Log the final decoded and cleaned email ID
console.log("Final Decoded Email ID:", decodedEmailId);
return decodedEmailId; // Return the cleaned email ID
}
function validate() {
var questions = [
{ name: "Question1", errorMessage: "Please select at least one option for Feature1." },
{ name: "Question1", errorMessage: "Please select at least one option for Feature2." },
{ name: "Question1", errorMessage: "Please select at least one option for Feature3." }
];
var isValid = true;
questions.forEach(function(question) {
var questionInputs = document.querySelectorAll('input[name="' + question.name + '"]');
var selectedAnswers = document.querySelectorAll('input[name="' + question.name + '"]:checked');
if (questionInputs.length > 0) {
if (selectedAnswers.length === 0) {
alert(question.errorMessage);
questionInputs[0].focus();
isValid = false; // Set to false if validation fails
} else {
selectedAnswers.forEach(function(answer) {
document.controller.setValue('/ctx/FOD_SurveyResponse/@' + question.name, answer.value);
});
}
}
});
if (isValid) {
// Submit the form
document.controller.submit('next', '_self', 'next');
}
return isValid;
// Return validation result
}
// ]]>
Now, can you explain how to access this encrypted string and pass it to the decryptString function within the JavaScript activity of the WebApp? I’m also working on a function that sets values upon form submission:
var emailId = getEmailFromUrl(); // Extract email ID from URL
var key256Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc"; // 256-bit key
var email_id = decryptString(emailId, key256Bytes); // Decrypt email ID
What I’m trying to achieve is to capture the customer’s response (typically a value between 1-10) and send that response to a backend table and specific column. I’m currently using document.controller.setValue('ctx/Fod_Survey/Question1') in client side, which works fine for capturing the response upon clicking on the submit button, but I’m struggling with the decryption part.
I am using the function below in a JavaScript file, but it seems that the email address is not being decrypted successfully. Although the question response is submitted, and I'm directed to the Thank You page, the encrypted emailId retrieved from the URL—whether decrypted or not—is not being passed to the email_address column in the table.
function valid() {
// Get email ID from URL
var emailId = getEmailFromUrl();
var key256Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc";
// Decrypt the email ID
var email_id = decryptString(emailId, key256Bytes);
// Initialize isValid
var isValid = true;
// Validate the email ID
if (!emailId || !email_id) {
alert("Error: Email ID is missing or invalid.");
isValid = false;
}
// Continue with validation if email is valid
if (isValid) {
// Set the value and submit the form
document.controller.setValue("/ctx/FOD_SurveyResponse/@Email_Address", email_id);
document.controller.submit('next', '_self', 'next');
}
// Return the validation status
return isValid;
}
Thanks in advance for your help!
Views
Replies
Total Likes
Hello @rvnth You don't have to use the function getEmailFromUrl(). The
Problem with this is that it runs on client side and the decryptString is a server-side function.
function getEmailFromUrl() {
var params = new URLSearchParams(window.location.search);
var encodedEmailId = params.get('email_id');
if (!encodedEmailId) {
return null; // No email_id found
}
Use this way to decrypt the email. Use as much out of the box functionality and don't write too much code.
Here is what you should do to
Hi @_Manoj_Kumar_ ,
When I use the decryption code directly inside the JavaScript activity, I encounter an error and am unable to access the page
Best,
Revanth
Views
Replies
Total Likes
Hi @_Manoj_Kumar_ ,
After reviewing the thread below,
I followed a similar approach and was able to access the page successfully. However, when I try to submit the form, I encounter an error.
Below is the code I am using in the JavaScript file:
ctx.vars.key32Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc";
ctx.vars.Email_Address = ctx.vars.Email_Address.toString();
ctx.vars.Email_Address = decryptString(ctx.vars.Email_Address,ctx.vars.key32Bytes);
Please suggest
Views
Replies
Total Likes
I initially had not declared the key32bytes in the WebApp properties variables, but I have now added it and can see the "Thank You" page after submission. However, the email address is still not being stored, despite selecting the email address in the Storage activity checkbox. Please advise.
Thank you in advance!
Views
Replies
Total Likes
Update: @_Manoj_Kumar_
I have used the following JavaScript code, but while the survey responses are being captured in the schema, the email address is not being recorded. Could you please provide some suggestions? Thank you in advance.
ctx.vars.key32Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc";
ctx.vars.Email_Address = ctx.vars.Email_Address.toString();
ctx.vars.Email_Address = decryptString(ctx.vars.Email_Address,ctx.vars.key32Bytes);
ctx.FOD_SurveyResponse.Email_Address = ctx.vars.Email_Address;
Views
Replies
Total Likes
Hi @_Manoj_Kumar_ ,
I have a follow-up question. Could you please guide me on how to check if a response has already been logged for a customer, and if so, how to redirect them to the 'Thank you' page?
I am trying to use a JavaScript activity just before the Page 4 activity, but I’m unsure whether I need to use queryDef, convert the result to a string, check if a response exists, and then redirect them to the 'Thank you' page.
Additionally, my form contains one or more questions, and if a response to a specific question already exists, I want to ensure that question is not displayed. Could you please suggest how I can achieve this? Thank you in advance.
Views
Replies
Total Likes
Hello @rvnth
In Javascript activity you can just use this
const decryptedEmail=decryptString(ctx.vars.email_id);
Views
Replies
Total Likes
Hi @_Manoj_Kumar_ ,
Thank you for your assistance. The code below successfully enabled me to decrypt the email string and store it in the corresponding schema column.
.
ctx.vars.key256Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc";
ctx.vars.Email_Address = ctx.vars.Email_Address.toString();
ctx.FOD_SurveyResponse.@Email_Address = decryptString(ctx.vars.Email_Address, ctx.vars.key256Bytes);
Views
Replies
Total Likes