I found this super helpful article in the forum to help write automation to send out the Customer Survey based on a specific resolution:
Current setup:
As the automation fires AFTER the Workflow, the above all works, EXCEPT :
If the Agent write a comment in the Completed Screen, everything works perfectly.
If the Agent does NOT write a comment, the code grabs the last comment from history (based off its name, this is expected behavior). The problem is that the last comment might be irrelevant and thus confusing.
Possible solutions:
add language to email that says “Last comment made by Agent (you might have already seen):”(clunky; not ideal)
making sure the Agent writes their final comments in the resolution screen and not in the body comments section (prone to human error, relies on education; not ideal)
Require the comments section on the Completed Screen (applies to ALL resolutions; do not want a comment when closing a ticket with a "duplicate" resolution; no ideal)
Add code to compare timeStamp of last comment to current time and if within determined range (say 30 seconds) then output the comment, if not don't. (ideal)
After researching it appears that javascript can be embedded in html code to perform actions.
However, I cannot get it to work. It could completely be user error (I am a total newb at this) and I missed something. OR javascript in html in an automated email script doesn't work. I did see one comment that it's not a good idea in general to embed javascript in html, so maybe I need to abandon this wish regardless.
Culled down to what you need, here is the code:
<pre><code>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<base href="removed">
</head>
<body>
<div class="jsm-message-content" style="margin-bottom: 30px">
<div class="jsd-activity-item-content">
<p>Your Agent: {{assignee.displayName}} changed the status to Done.</p>
<p>Last comment from history: {{issue.comments.last.body}} </p>
<p>Timestamp of last comment from history: {{issue.comments.last.created}} </p>
<p>script output should be here:</p>
<script>
window.onload = function() {
// Simulate the {{issue.comments.last.created}} variable (replace this with the actual value in your context)
var commentTime = "{{issue.comments.last.created}}"; // This will be replaced by the actual timestamp
var commentDate = new Date(commentTime);
// Get current time
var currentTime = new Date();
// Calculate the difference in seconds
var timeDiffInSeconds = (currentTime - commentDate) / 1000;
// Check if the difference is less than 30 seconds
if (timeDiffInSeconds < 30) {
document.getElementById('result').innerText = "Comment entered on closure";
} else {
document.getElementById('result').innerText = "Comment not entered within 30 seconds of closure";
}
};
</script>
<div id="result"></div>
</div>
</body>
</html>
</code></pre>
Here's the output:
----
Your Agent: AgentNameRemoved changed the status to Done.
Last comment from history: comment entered in resolution screen
Timestamp of last comment from history: 2024-11-13T21:18:33.0+0000
script output should be here:
----
No output after that last line.
I have read the timestamp isn't the right format, but I replaced it with the hardcoded proper format and still nothing.
Any other ideas? Or will this just not work or is not allowed?
Thanks for any advice!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.