0

I am trying to upload date column value in SharePoint list column of "date and time" type.

The below image of excel data:

enter image description here

The "Date of Commissioning" value upload in SharePoint list "date and time" column.

The value I am getting when I am upload the date in list is given in below image:

enter image description here

The code I have used for upload the date is given below:

function insertdata(response) {
    // var vmnamevalue = new Array();
    var deferred = $.Deferred();
    var i = 0;
    //var loc1 = '';
    var ListName = "TestDetails";
    var context = new SP.ClientContext.get_current();
    var lstObject = context.get_web().get_lists().getByTitle(ListName);
    var listItemCreationInfo = new SP.ListItemCreationInformation();
    var newItem = lstObject.addItem(listItemCreationInfo);

    for (i = 0; i < response.length; i++) {

        var cName = $("#txtCompanyname").val();
        var companyName = response[i]["Name of Company"];
        vmname = response[i].VMName;
        gIPAddress = response[i]["Guest IP Address"];
        $("#currentItem").html("<b>" + "VM = " + vmname + "and IP Address = " + gIPAddress + "</b>"); //VMName

        var physicalVirtual = response[i]["Physical / Virtual"];

        if (cName === companyName && vmname !== undefined && gIPAddress !== undefined) {
            newItem.set_item('UID', generateUUID());
            newItem.set_item("FileID", randomNumberBetween0and200000);
            newItem.set_item('EmployeeName', empname);
            newItem.set_item("EmpEmail", empemail);
            newItem.set_item("SubmissionDate", subdate);

             newItem.set_item('CommissioningDate', response[i]["Date of Commissioning"]);
            //newItem.set_item('RequestorCommissioning', response[i]["Requestor of Commissioning"]);
           
            newItem.update();

            context.executeQueryAsync(onSuccess, onFailure);

            done++;

        } else if (vmname == undefined && gIPAddress == undefined) {
            console.log("VM Name OR IP Address is blank");
        }
        else {
            console.log("Company name is not match");
        }
    }

    function onSuccess() {

       var complete = ((done / totalItems) * 100);
        complete = Math.floor(complete) + '%';
        $("#uploadBar").css({
            "width": complete
        });
        $("#uploadBar").html(complete + " Complete");
    }

    function onFailure(sender, args) {
        if (vmname == undefined) {
            alert('VM Name is blank ');
        } else if (gIPAddress == undefined) {
            alert('IP Address is blank ');
        } else {
            alert('Request failed for Server Details ');
        }
        done--;
        var complete = ((done / totalItems) * 100);
        complete = Math.floor(complete) + '%';
        $("#uploadBar").css({
            "width": complete
        });
        $("#uploadBar").html(complete + " Complete");
        console.log(args.get_message() + '\n' + args.get_stackTrace());
    }
}
2
  • Try using: newItem.set_item('CommissioningDate', new Date(response[i]["Date of Commissioning"]));. let me know if it works for you. Sep 7 at 7:39
  • It not works for me. I would like to upload the date which is given in the excel not current date.
    – Shreya
    Sep 7 at 8:45

Your Answer

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

Browse other questions tagged or ask your own question.