Blog

Service Portal: Watchlist Widget

Add a watchlist widget to your Ticket form in Service Portal.  Allow self service users to add email addresses to the watchlist.

This just allows watchlist users to get emails on the ticket.  To allow watchlist users view the ticket in the Service Portal, you'll have to adjust your ACLs and SP configuration.

Email Format Check

Auto Complete

Confirmation Message

Widget

Name: Ticket Watchlist
ID: ticket_watchlist

HTML

<div class="panel panel-{{::options.color}} b">
<div class="panel-heading">
<h4 class="panel-title"><fa ng-if="::options.glyph.length" name="{{::options.glyph}}" class="m-r-sm" />Add to Watchlist</h4>
</div>
<div class="panel-body">
<form ng-submit="server.update()">
${Enter an email address to follow}
<div class="textbox_space">
<input ng-model="data.watch_list" id="watch_list" class="form-control" type="email" maxlength="50" />
</div>
<input type="submit" id="submit" value="{{data.submitMsg}}" class="btn btn-primary" style="margin-top: 5px;margin-bottom: 5px;"/>
<div ng-if="data.response" class="alert alert-success">{{::data.response}}</div>
</form>
</div>
</div>

CSS

.textbox_space {
margin-top: 10px;
margin-bottom: 10px;
}

Client Script

function() {
/* widget controller */
var c = this;
}


Server Script

(function() {
data.submitMsg = gs.getMessage("Add");
data.sys_id = $sp.getParameter('sys_id');
if (input) {
data.sys_id = input.sys_id;
data.watch_list = "";
var grTask = GlideRecord("task");
grTask.query("sys_id", data.sys_id);
grTask.query();
data.response = gs.getMessage('Thank you, email was added.');
//console.log('grTask Query: ' + grTask.getEncodedQuery() + ' = ' + grTask.getRowCount());
if (grTask.next()) {
var wList = grTask.watch_list;
var wEmail = input.watch_list;
var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', wEmail);
grUser.query();
if (grUser.next()) {
// It's a user
if(wList != "") {
wList = (wList + "," + grUser.sys_id);
} else {
wList = grUser.sys_id;
}
} else {
//It's not a user either...so just add the address to the list...except instance email address
wList = (wList + "," + wEmail);
}
grTask.watch_list = wList;
grTask.update();
}
}
})();

Fields: Bootstrap color, Glyph