Problem with UpdateListItem

Jan 7, 2011 at 3:51 PM
Edited Jan 7, 2011 at 7:10 PM

Hi,

 Am trying to update a list column DaysAvailable. The value is not getting updated in the list..Code is defined in presaveaction(). Please see below for the code.      

DaysLeft is a field in the newform.aspx. Getting a SOAP exception : key in dictionary : undefined key being added: undefined

Could u plz tell me what's wrong??

 

var daysLeft = setFieldValue('DaysLeft',avdays,false);

       var daysleft1 = $("input#DaysLeft").val(); // Is this right??

                $().SPServices({

                        operation: "UpdateListItems",
                        async: false,
                        listName: "Vacation Days",
                        valuepairs: ["DaysAvailable",avdays],
                        id: thisID,
                       completefunc: function(xData, Status) {
                            alert(xData.responseText);
                            alert(xData.responseXML.xml);
                            alert("completed");
             }
               });

 

 Please find the entire code...

function PreSaveAction() {

var calEvent = getTagFromIdentifierAndTitle("SELECT","DropDownChoice","Calendar Event");

   if(calEvent.value == 'Vacation'){

        var thisUserAccount =

        $().SPServices.SPGetCurrentUser({

                fieldName: "Name",

                debug: false

   });

   $(document).ready(function() {

         $().SPServices({

         operation: "GetListItems",

         async: false,

         listName: "Vacation Days",

       CAMLViewFields: "<ViewFields><FieldRef Name='EmpName'/><FieldRef Name='Days'/></ViewFields>",

         completefunc: function (xData, Status) {

                                       $(xData.responseXML).find("[nodeName=z:row]").each(function()   {

                 var empname = $(this).attr("ows_EmpName");

                 var thisValue = (empname.split("#"))[1];

                  var thisID = $(this).attr("ows_ID");

                 var totaldays = 0;

                 if (thisUserAccount == thisValue ){

                           totaldays = parseInt($(this).attr("ows_Days")).toString();

                  

                   }

                   else {

                           totaldays = " ";

                       };

                     alert("totaldays = "+totaldays);

                     var date1 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Start Time");

                     var date2 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","End Time");

                     var startDate1 = new Date(date1.value);

                     var endDate1 = new Date(date2.value);

                     if(startDate1>endDate1){

                           alert("Your Start Date is later than your End Date");

                   return;

                   }

                   if(endDate1<startDate1){

                          alert("Your End Date is earlier than your Start Date");

                   return;

                   }

                 var halfDay = getTagFromIdentifierAndTitle ("select","DropDownChoice","Half Day");

                 var days = 0;

                if (halfDay.value=="Yes") {

                   days = 0.5;

               //alert("days ="+days);

               }

               else {

               //alert("Hi");

             days = calcBusinessDays(date1,date2);

             alert("days ="+days);

             }

           fields = init_fields_v2();

           var avdays = totaldays - days;

           alert("avdays = "+avdays);

         // Set the value for textboxes

         var daysApplied = setFieldValue('Days',days,false);

       var daysLeft = setFieldValue('DaysLeft',avdays,false);

       var daysleft1 = $("input#DaysLeft").val();

                   $().SPServices({

                       operation: "UpdateListItems",

                                async: false,

                                listName: "Vacation Days",

                             batchCmd: "Update", 

                                valuepairs: ["DaysAvailable",avdays],

                                id: thisID,

                                completefunc: function(xData, Status) {

                              alert(xData.responseText);

                                   alert(xData.responseXML.xml);

                                   alert("completed");

                                }

                  });

 

                              

             }); // xData.responseXML

   } //completefunction

}); //SPServices

}); // ready

 

 

} //IF

return true;

} //presave

Thanks

sappai

Coordinator
Jan 7, 2011 at 9:49 PM

sappai:

I don't think that some of your SPServices stuff is ever getting called. You have some of your script wrapped in $(document).ready inside your PreSaveAction, which doesn't really make sense. 

I think you need to keep debugging, using the alerts to see what code sections are running and which aren't. I'd suggest skinnying it way down and then building up bit by bit.

M.