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" };
    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,
        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 () {

        error: function (Rep, textStatus, errorThrown) {
            console.log("Update failed." + Rep.responseText + " " + errorThrown.toString())


function onError(error) {


With this code i just get the Login name.I want to get the date and time too when clicking Approver

  • Do you want to to get the date and time when user clicks on the approver button or something else?? – Ganesh Sanap Oct 25 '18 at 9:56

In javascript code, you can get the date and time very easily with following code:

var dateTimeNow = new Date();

If you want to store this date & time in list:

  1. By default in SharePoint we get "Created" column which stores the date time whenever we add new item in list.

  2. And if you want to store this time in another field on your own, you need to add one more column in list and one property in your data("Linked") which you are using in POST call.

  3. For this you need to pass the date in ISO format. You can convert your date in ISO format using following code:

var isoFormatedDate = dateTimeNow.toISOString();

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.