My HTML code is :
<button id="app1" type="button"onclick="javascript:Approver(ProspectID);">Approver</button>
My JS code :
function Approver(ProspectID) {
var userid = _spPageContextInfo.userId;
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestHeaders = { "accept": "application/json;odata=verbose" };
$.ajax({
url: requestUri,
contentType: "application/json;odata=verbose",
headers: requestHeaders,
success: onSuccess,
error: onError
});
function onSuccess(data, request) {
var loginName = data.d.Title;
var itemType = GetItemTypeForListName(ListNameProspect);
var Linked = {
"__metadata": { "type": itemType },
"Approverun": loginName,
};
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('" + ListNameProspect + "')/items(" + ProspectID + ")",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(Linked),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": "*"
},
success: function () {
RetrieveProspect(ProspectID);
},
error: function (Rep, textStatus, errorThrown) {
console.log("Update failed." + Rep.responseText + " " + errorThrown.toString())
}
});
}
function onError(error) {
alert("error");
}
}
With this code i just get the Login name.I want to get the date and time too when clicking Approver