Hi All! I am looking to calculate tenure (based on embedded data coming from SFDC) for a customer that responds to a survey. The format of the date is Year-Month-Day. I don’t have a ton of experience with custom coding. Any help or guidance would be greatly appreciated!
Page 1 / 1
You can use JavaScript and the Luxon library.
Add Luxon to your survey header in source mode:
<script src="https://cdn.jsdelivr.net/npm/luxon@3.4/build/global/luxon.min.js"></script>
Add JS something like this a question:
Qualtrics.SurveyEngine.addOnload(function() {
var DateTime = luxon.DateTime;
var startDate = DateTime.fromFormat("${e://Field/SFDC}","YYYY-MM-dd");
var tenure = DateTime.now().diff(startDate, ['years','months']).toObject();
Qualtrics.SurveyEngine.setEmbeddedData('tenure',tenure.years);
});
Thank you
No ‘var’ is a JavaScript command that declares variable names. Don’t change it. I did have the year token wrong. It should be:
Qualtrics.SurveyEngine.addOnload(function() {
var DateTime = luxon.DateTime;
var startDate = DateTime.fromFormat("${e://Field/SFDC}","yyyy-MM-dd");
var tenure = DateTime.now().diff(startDate, t'years','months']).toObject();
Qualtrics.SurveyEngine.setEmbeddedData('tenure',tenure.years);
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.