Add button in the calculated field in SharePoint 2013 list definition:
<Field Name=”Accept” ID=”{1F7328C7-D7F0-4B94-BB15-01859CD28CF2}” DisplayName=”AcceptorDecline” Type=”Calculated” ResultType=”Number” ReadOnly=”TRUE” JSLink=”/_layouts/15/CCAR.SP.Common.Lists/UserRecertification/UserRecertificationScripts.js”>
<Formula>
=”<div id=’divAccept’> <input type=’button’ name=’btnAccept’ id=’btnAccept’ onclick=””UpdateApproveorDecline(‘”&[URID]&”‘,’Yes’)”” value=’Approve’/>
<input type=’button’ name=’btnDecline’ id=’btnDecline’ onclick=””UpdateApproveorDecline(‘”&[URID]&”‘,’No’)”” value=’Decline’ /></div>”
</Formula>
<FieldRefs>
<FieldRef Name=”URID” />
</FieldRefs>
</Field>
//UserRecertificationScripts.js code
function UpdateApproveorDecline(URID, ApproveorDecline) {
if (!isEmpty(URID))
{
GetListID(URID, ApproveorDecline);
}
}
function GetListID(URID, ApproveorDecline)
{
if (!isEmpty(URID))
{
var clientContext = new SP.ClientContext.get_current();
if (!isEmpty(clientContext))
{
var webSite = clientContext.get_web();
var list = webSite.get_lists().getByTitle(‘User Recertification’);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(‘<View><Query><Where><Eq><FieldRef Name=\’URID\’/><Value Type=\’Text\’>’ + URID + ‘</Value></Eq></Where></Query></View>’);
this.collListItem = list.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args)
{
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext())
{
//Get the current item then get the item ID
var currentItem = listItemEnumerator.get_current();
//Getting the values to pass to the popup function
var itemid = currentItem.get_item(“ID”);
UpdateListItem(itemid,ApproveorDecline)
}
}),
Function.createDelegate(this, OnLoadFailed));
}
}
}
function UpdateListItem(itemid, ApproveorDecline)
{
if (!isEmpty(itemid))
{
var clientContext = new SP.ClientContext.get_current();
if (!isEmpty(clientContext))
{
var webSite = clientContext.get_web();
var list = webSite.get_lists().getByTitle(‘User Recertification’);
this.oListItem = list.getItemById(itemid);
oListItem.set_item(‘Accept_x002f_Decline’, ApproveorDecline);
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args)
{
alert(“Accept/Decline set to ” + ApproveorDecline);
}),
Function.createDelegate(this, OnLoadFailed));
}
}
}
function OnLoadFailed(sender, args) {
//Displays an error in case the request fails
alert(“Request Failed: JSOM Error, ” + args.get_message() + ‘\n’ + args.get_stackTrace());
}