Hello guys!
We have a case where we want to delay the execution of a task within a workflow for one hour. This is because when the customer service case (within out CRM) get's closed, it automatically sends out the information to the Qualtrics' workflow (A Json Event) to send out the survey with an XM Directory Task. But if we send the response to the case (CRM) and the survey (Qualtrics) at the same time, it's possible that the user sees the survey invitation before seing the response to their case. Also, we have had some cases where the survey arrives first than the response to the case.
For that, we want to use a code task to delay the execution of the survey distribution. But we haven't been able to do so.
the most logic way of doing thos would be the setTimeout() function in JS. But that's not working Here's one examples of many codes that we have tried in a generic console and worked but that fails in Qualtrics:
function codeTask(){
return {
validador:"1",
};}
setTimeout(codeTask, 60000)
Do you guys think that this is posbile?
Thanks!
Ricmarug
Your use case is possible but the approach is wrong. Code task is also essentially a task and would not create a delay between the trigger and task.
To do this you need to calculate time within javascript like +one hour from the survey recorded date. Include the below on your last question of survey. Create an embedded data sendDate in your survey flow which you can use in webservice later.
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
{/*Place your JavaScript here to run when the page loads*/
const date = new Date('${date://CurrentDate/c}');
function addHours(numOfHours, date = new Date()) {
const dateCopy = new Date(date.getTime());
dateCopy.setTime(dateCopy.getTime() + numOfHours * 60 * 60 * 1000);
return dateCopy;
}
const result = addHours(1, date);
console.log(result);
Qualtrics.SurveyEngine.setEmbeddedData('sendDate',result);
});
Then use this API in a webservice task to send out the survey where the send date would be the one you calculated and pushed in an embedded data.
Hope it helps!
Hello Deepak!
I liked your approach, it's very interesting. The thing here is that I'm not getting the information from a survey so I can't really put it on the survey flow.
I'm receiving the payload with a Json event (my IT team has a job that sends me all the info of the cases from the CRM to the Json event once the case is closed).
My idea was to have 2 tasks, the delay and the xm directory task.
The delay task (code task) won't delay the excecution of the xm directory task as such. What I'm trying to do is that the code task takes that amount of time to execute (60*60*1000 ms) the creation of a variable (any variable) let's say variable1 = 1.
Then, in the XM directory task I can set that variable as an embedded data so that I can define the order in which the flows are executed.
Do you see that possible?
Ricmarug
Yes, you can create two tasks have an output of the code task and based on that condition you can run the below task.
Hope it helps!
Hi
Hello
Yep, I was able to. I run this code task:
function codeTask() {
var fechaHoy = new Date()
var fechaexpire = new Date()
var daysexpire = 10
var numberOfMlSeconds = fechaHoy.getTime();
var addMlSeconds = 3600000;
var newDateObj_send = new Date(numberOfMlSeconds + addMlSeconds);
fechaexpire.setDate(newDateObj_send.getDate()+daysexpire);
return {
fechaHoy,
newDateObj_send,
fechaexpire
}
}
Where
fechaHoy = current date.
newDateObj_send = send date (the delay is defined by addMlSeconds in miliseconds)
fechaexpire = expiration date. In this example it’s 10 days after send date. Defined by daysexpire
Then you can use the api mentioned by Deepak on his first response in a webservice task. (this is assuming that you already have the contact or transactions if needed)
Hope this helps!
Hi
If I understand correctly, this delay the sending of the survey rather than delaying the execution of the actual task?
That’s correct! the delay is on the distribution side. You can see them as programmed distributions in the XM Directory.
I wasn’t able to create the delay on the task because they run 1 after the other. So even if I had a code that makes a delay (that is not possible because the settimeout function is not allowed on code task), when the code task ends, the next task begins. So it wasn’t possible.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.