none
context.executeQueryAsync function is not working in edit mode of custom page having jquery code? RRS feed

  • Question

  • Here is my Save button code.In this while creation of the item this code is working fine.In edit mode,if again click on Save,these data should be updated.but here context.executeQueryAsync function is not working.Debug point is not going inside of this function.

    Please help where i have to modify to work this code.

                     

    function SaveFieldInfo(flag,is_Submitted)
    {
    var doctyp = $("#documenttype").val();
    var othrtyp = $("#othertype").val();
    var docname = $("#documentname").val();

    var peoplePicker1 = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDivAppr1_TopSpan;
             var users1 = peoplePicker1.GetAllUserInfo();
    var peoplePicker2 = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDivAppr2_TopSpan;
             var users2 = peoplePicker2.GetAllUserInfo();
    var peoplePicker3 = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDivAppr3_TopSpan;         

    var userids = {};
    var context = new SP.ClientContext.get_current();
    if (users1.length > 0)
    {
    userids.user1 = context.get_web().ensureUser(users1[0].Key);
    context.load(userids.user1);
    }
    if (users2.length > 0) 
    {
    userids.user2 = context.get_web().ensureUser(users2[0].Key);
    context.load(userids.user2);
    }
    context.executeQueryAsync(  //Issue HERE -debug point not going inside the function. 
              Function.createDelegate(null, function() {
    deferred.resolve(approvers);
    if (users1.length > 0){
    approvers.appr1 = userids.user1.get_id();
    }
    else{
    approvers.appr1="";
    }
    if (users2.length > 0)
    {
    approvers.appr2 = userids.user2.get_id();
    }
    else{
    approvers.appr2="";
    }

                  if( lastUniqueID =="" )
    {
    var batchScore = "<Method ID='1' Cmd='New'><Field Name='Title'>" + reqnum + "</Field>\
    <Field Name='DocumentType'>" + doctyp + "</Field>\
    <Field Name='OtherType'>" + othrtyp + "</Field> \
    <Field Name='DocumentName'>" + docname + "</Field>\
    <Field Name='Approver_x0020_1'>" + approvers.appr1 + "</Field> \
    <Field Name='Approver_x0020_2'>" + approvers.appr2 + "</Field>\</Method>";
    }

        else {

                var batchScore = "<Method ID='1' Cmd='Update'><Field Name='Title'>" + reqnum + "</Field> \
    <Field Name='DocumentType'>" + doctyp + "</Field> \
    <Field Name='OtherType'>" + othrtyp + "</Field> \
    <Field Name='Approver_x0020_1'>" + approvers.appr1 + "</Field> \
    <Field Name='Approver_x0020_2'>" + approvers.appr2 + "</Field>\</Method>";

    }

                   var soapEnv = "<?xml version=\'1.0\' encoding=\'utf-8\'?> \
    <soap:Envelope xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' \
    xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\' \
    xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/\'> \
    <soap:Body> \
    <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
    <listName>Document Approval Request</listName> \
    <updates> \
    <Batch OnError='Continue'  ListVersion='1' ViewName='89fccf86-3e0e-411e-9a8e-e924dfb0d0bf'>" + batchScore + "</Batch> \
    </updates> \
    </UpdateListItems> \
    </soap:Body> \
    </soap:Envelope>";

    $.ajax({

    url: HRConstants.ServiceUrl,
    contentType: "text/xml; charset=utf-8",
    beforeSend: function (xhr) {
    xhr.setRequestHeader("SOAPAction",
    "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
    },
    type: "POST",
    asyc: false,
    dataType: "xml", 
    data: soapEnv,
    complete: Result,
    error : addRequestFailed
    });
    function Result(xData, status) {

    if(status=='success')
    {
    alert("Items Added");
    }
    else 
    {
    alert('Error Occurred. Please try again after some time.');
    }
    }
    function addRequestFailed(xhr, status, error) 
    {
                       alert("Error occured");
                    }
    }), 
             Function.createDelegate(null, function(sender, args) {
    alert('Query failed. Error: ' + args.get_message());
    })
        );
    }


    Friday, February 10, 2017 3:00 PM

All replies