Add callout cu​stom action based on content TYPE

Posted on

I had a strange requirement this week.  We have a document library with 3000 items where there is a workflow that was approved by the users some months ago, the workflow is quite complex.

However after some months using it, the users complain that some documents dont need the long approval and can just go to Completed.

The status field is of course a hidden field, so they cant just modify it, normally the workflow would update this field for the users.



​​Create a callout custom action, for those who dont know the callout its the small pop window that appears when you click on the 3 dots in a document library item.

Callouts are not limited to list items, they can be done everywhere in every element you want, and they are used extensively in search results as display templates.

In  my case I didnt need to put the custom action in search results, just in the document library.


​​1. ​add code snippet webpart

​The code below is for a normal document library, as I was working during the weekend at home, I did it on my sharepoint online (Documents Library),  but in your environment you only need to change the list title and the field you want to change.

SP.SOD.executeFunc("callout.js", "Callout", function () {
var itemCtx = {};
itemCtx.Templates = {};
itemCtx.BaseViewID = 'Callout';
// Define the list template type
itemCtx.ListTemplateType = 101;

itemCtx.Templates.Footer = function (itemCtx) {
return CalloutRenderFooterTemplate(itemCtx, AddCustomCompleteAction, true);


function AddCustomCompleteAction (renderCtx, calloutActionMenu) {
if(renderCtx.CurrentItem.ContentType=='Document') {
calloutActionMenu.addAction (new CalloutAction ({
text: 'COMPLETE',
tooltip: 'This action will set status to Complete, this action cant be rolled back.',
onClickCallback: function() {UpdateBillCycleStatusToCompleted(1);}

// Show the default document library actions
CalloutOnPostRenderTemplate(renderCtx, calloutActionMenu);

// Show the follow action
calloutActionMenu.addAction(new CalloutAction({
text: Strings.STS.L_CalloutFollowAction,
tooltip: Strings.STS.L_CalloutFollowAction_Tooltip,
onClickCallback: function (calloutActionClickEvent, calloutAction) {
var callout = GetCalloutFromRenderCtx(renderCtx);
if (!(typeof(callout) === 'undefined' || callout === null))
SP.SOD.executeFunc('followingcommon.js', 'FollowSelectedDocument', function() { FollowSelectedDocument(renderCtx); });

function UpdateBillCycleStatusToCompleted(itemId) {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Documents');
this.oListItem = oList.getItemById(itemId);
oListItem.set_item('Title', 'Complet');
clientContext.executeQueryAsync(Function.createDelegate(this, this.StatusCompletedSucceeded), Function.createDelegate(this, this.StatusCompletedFailed));

function StatusCompletedSucceeded() {
alert('Item updated!');

function StatusCompletedFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

function IsCurrentUserMemberOfGroup(groupName, callback) {
var currentContext = new SP.ClientContext.get_current();
var currentWeb = currentContext.get_web();

var currentUser = currentContext.get_web().get_currentUser();

var allGroups = currentWeb.get_siteGroups();

var group = allGroups.getByName(groupName);

var groupUsers = group.get_users();


function OnSuccess(sender, args) {
var userInGroup = false;
var groupUserEnumerator = groupUsers.getEnumerator();
while (groupUserEnumerator.moveNext()) {
var groupUser = groupUserEnumerator.get_current();
if (groupUser.get_id() == currentUser.get_id()) {
userInGroup = true;

function OnFailure(sender, args) {

​2. next challenge.

​Now I need to show the option based on the current user group, if the user its in a specific group, then show the custom action, otherwise dont show it, that will be my next blog post.


Hope you enjoy it, I had fun times coding this.

Thanks to : @eliostruyf​​​


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s