<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Acknowledge button in email notifications in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/acknowledge-button-in-email-notifications/m-p/458124#M29903</link>
    <description>&lt;P&gt;What I don't know here is how to reply to the email with just clicking link inside the body.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Apr 2020 15:05:47 GMT</pubDate>
    <dc:creator>Niuk</dc:creator>
    <dc:date>2020-04-15T15:05:47Z</dc:date>
    <item>
      <title>Acknowledge button in email notifications</title>
      <link>https://www.servicenow.com/community/itsm-forum/acknowledge-button-in-email-notifications/m-p/458122#M29901</link>
      <description>&lt;P&gt;I have been trying to make an acknowledge link similar to the approval/disapproval link for change requests that I believe is the default in ServiceNow.&amp;nbsp;I saw the "&lt;EM&gt;On-Call: Assign by Acknowledgement "and "Update Approval Request"&amp;nbsp;&lt;/EM&gt;that an email is sent back to the instance which updates the appropriate field&lt;EM&gt;.&lt;/EM&gt;&amp;nbsp;I am not sure how those work though as there is a lot going on. Then I also see&lt;EM&gt;&amp;nbsp;"Update Case via AcceptReject"&amp;nbsp;&lt;/EM&gt;and "&lt;EM&gt;Update Case via reply"&amp;nbsp;&lt;/EM&gt;which have some simple JS that changes the state of the approval. Not sure which is used for which though.&lt;/P&gt;
&lt;P&gt;So I figure for my acknowledge button/hyperlink I could&amp;nbsp;use in the HTML:&lt;/P&gt;
&lt;P&gt;${mailto:mailto.approval}&lt;BR /&gt;&lt;BR /&gt;${mailto:mailto.rejection}&lt;/P&gt;
&lt;P&gt;I thought this because it seems for both the change approval and acknowledge approval, ServiceNow is looking for a reply with the word "approval" in the subject if it finds it changes the state of approval or in this case the&amp;nbsp;acknowledged field. But that didn't work.&lt;/P&gt;
&lt;P&gt;Here are the scripts for each of the actions below if anyone can help me create this acknowledge button.&lt;/P&gt;
&lt;P&gt;The easy:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Update Case via AcceptReject&lt;/EM&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;if (current.state == 6) {
	var subject = email.subject.trim().toLowerCase();
	if(subject.indexOf("reject") === 0){
		current.state = 10;
	}else if(subject.indexOf("accept") === 0){
		current.state = 3;
	}
	current.update();
}

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;Update Case via reply&lt;/EM&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;//if case.state = resloved (6), then check first word in body for accept or reject
//else if case.state = Awaiting (18), then, move to open state
var case_state = current.state;
if (current.state == 6) {
	var lines = email.body_text.split('\n');
	var firstword = "";
	if (lines.length &amp;gt; 0)
		firstword = lines[0].replace(/^\s+|\s+$/g,'');
	firstline = firstword.toLowerCase();
	if (firstline) {
		if(firstline.indexOf("reject") == 0)
			current.state = 10;
		else if(firstline.indexOf("accept") == 0)
			current.state = 3;
	}
} else if (current.state == 18) {
	current.state = 10;
} else{
	current.sys_updated_on = "";
}

current.update();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The more difficult:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;On-Call: Assign by Acknowledgement&lt;/EM&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var assignedTo = current.getElement("assigned_to");

// if current is already assigned then do nothing
if (assignedTo !== null &amp;amp;&amp;amp; assignedTo.nil()) {
	// original message sent to user from on-call: assign by acknowledgement workflow
	var className = current.getValue("sys_class_name");
	className = className.charAt(0).toUpperCase() + className.slice(1);
	var emailMessage = gs.getMessage("You are being asked to assign yourself to {0}. To accept and assign yourself to the {1} reply to this email with 'ACC'. To reject reply to this email with 'REJ'. Rejecting will move this assignment process to the next person in your roster.", [current.getValue("number"), className]);

	if (email.body_text.indexOf(emailMessage) != -1) {
		// strip out the original email text that was sent out to the user "Reply with 'ACC' or 'REJ'"
		var str = email.body_text.replace(emailMessage, "");

		// match first occurrence of our expected response
		var regex = new SNC.Regex("/([0-9]*)(ACC|REJ)/i");
		var match = regex.match(str);

		// process valid response
		if (match !== null) {
			if (match.pop().equalsIgnoreCase("ACC")) {
				current.assigned_to = gs.getUserID();
				current.update();
			}

			// resume the workflow
			var wfScriptApi = new SNC.WorkflowScriptAPI();
			var wfContext = new GlideRecord("wf_context");
			wfContext.addQuery("workflow.name", "On-Call: Assign by Acknowledgement per Rota");
			wfContext.addQuery("id", current.getUniqueValue());
			wfContext.query();

			while (wfContext.next())
				wfScriptApi.broadcastEvent(wfContext.getUniqueValue(), "resume");
		}
	}
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Update Approval Request&lt;/EM&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;/*global current, email, gs, GlideController, GlideRecord*/
/*eslint-disable eqeqeq*/
processApprovalEmail();

function processApprovalEmail() {
	"use strict";
	var errorMsg = "";
	var msgArray = [];

	if (current.getTableName() != "sysapproval_approver")
		return;

	var displayValue = getApprovalDisplayValue(current);

	if (!validUser()) {
		gs.log(getFailurePreamble() + "Sender email does not match approval assignee.");
		msgArray.push(displayValue);
		msgArray.push(current.approver.getDisplayValue());
		msgArray.push(current.approver.email);
		errorMsg = gs.getMessage("approvalInvalidUser", msgArray);
		createEmailEvent(errorMsg);
		return;
	}

	if (current.state == 'cancelled') {
		gs.log(getFailurePreamble() + "The approval has been canceled.");
		msgArray.push(displayValue);
		errorMsg = gs.getMessage("approvalCancelled", msgArray);
		createEmailEvent(errorMsg);
		return;
	}

	if (email.body.state != undefined)
		current.state = email.body.state;

	if (email.subject.indexOf("approve") &amp;gt;= 0)
		current.state = "approved";

	if (email.subject.indexOf("reject") &amp;gt;= 0)
		current.state = "rejected";

	if (current.state != "approved" &amp;amp;&amp;amp; current.state != "rejected") {
		gs.log(getFailurePreamble() + "The subject is malformed. The approver probably did not click the approve or reject button on the email.");
		msgArray.push(displayValue);
		errorMsg = gs.getMessage("approvalFailed", msgArray);
		createEmailEvent(errorMsg);
		return;
	}

	current.comments = "reply from: " + email.from + "\n\n" + email.body_text;
	var controller = new GlideController();
	controller.putGlobal("approvalSource", "email");
	current.update();
	controller.removeGlobal("approvalSource");

	function validUser() {
		if (current.approver == email.from_sys_id)
			return true;

		// check if the email is from a delegate of the approver
		var g = new GlideRecord("sys_user_delegate");
		g.addQuery("user", current.approver.toString());
		g.addQuery("delegate", email.from_sys_id);
		g.addQuery("approvals", "true");
		g.addQuery("starts", "&amp;lt;=", gs.daysAgo(0));
		g.addQuery("ends", "&amp;gt;=", gs.daysAgo(0));
		g.query();
		return g.hasNext();
	}

	function createEmailEvent(msg) {
		gs.eventQueue("approval.email.errorMsg", current, email.from, msg);
	}

	function getFailurePreamble() {
		return 'Approval email from ' + email.from + ' for task "' + displayValue + '" assigned to "' + current.approver.getDisplayValue()
				+ '" failed because: ';
	}

	function getApprovalDisplayValue(approval) {
		if (!gs.nil(approval.sysapproval))
			return approval.getDisplayValue();
		else {
			var target = new GlideRecord(approval.source_table);
			if (target.get(approval.document_id))
				return target.getDisplayValue();
		}
		gs.warn("Target for sysapproval_approver:" + approval.getUniqueValue() + " not found. Target=" + approval.source_table + ":" + approval.document_id);
		return "Unknown";
	}

}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Apr 2020 12:56:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/acknowledge-button-in-email-notifications/m-p/458122#M29901</guid>
      <dc:creator>Ted18</dc:creator>
      <dc:date>2020-04-06T12:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Acknowledge button in email notifications</title>
      <link>https://www.servicenow.com/community/itsm-forum/acknowledge-button-in-email-notifications/m-p/458123#M29902</link>
      <description>&lt;P&gt;If you include these email templates in your notification, all they are doing is pre-populating the email subject line with Approve or Reject etc:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/16664i057A4486D2EDAFD4/image-size/large?v=v2&amp;amp;px=999" srcset="/community/image/serverpage/image-id/16664i057A4486D2EDAFD4/image-size/large?v=v2&amp;amp;px=999 1.0x" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in your reply inbound actions, you can read that subject line and check if it 'contains' your keyword. Something like:&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;if (email.subject.toLowerCase().indexOf("accept")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;this line would evaluate to true if the email subject contains the word 'accept'. &lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 13:30:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/acknowledge-button-in-email-notifications/m-p/458123#M29902</guid>
      <dc:creator>Michael Fry1</dc:creator>
      <dc:date>2020-04-07T13:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Acknowledge button in email notifications</title>
      <link>https://www.servicenow.com/community/itsm-forum/acknowledge-button-in-email-notifications/m-p/458124#M29903</link>
      <description>&lt;P&gt;What I don't know here is how to reply to the email with just clicking link inside the body.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 15:05:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/acknowledge-button-in-email-notifications/m-p/458124#M29903</guid>
      <dc:creator>Niuk</dc:creator>
      <dc:date>2020-04-15T15:05:47Z</dc:date>
    </item>
  </channel>
</rss>

