Date bug upon redirection  ?

I am using JSOM to create list item and redirect user from new form to edit form. I am using the same script in edit form to save and redirect  to display form. For redirection, I am using window.location.href = the site url + the list item ID as parameter.

It works fine but, there are 3 date fields and all of them get subtracted by one day upon redirection.For e.x., if I have a date field, Due Date and if I set the date as 5/21/2015, then upon redirection to edit form, this becomes 5/20/2015 and finally upon redirection to display form this becomes 5/19/2015.

I am not doing any date manipulation. I am just checking if the date field is not blank and then I am storing the same without altering anything.

So why is the date getting subtracted???

May 22nd, 2015 8:15am

Hi,

Would you mind providing the complete code in use for a further research? It would make others easier to find a solution for you.

I suggest you debug the code in browser using IE Developer Tools to see if the date value has been submitted correctly to a list.

About how to debug JavaScript using IE Developer Tools:

https://msdn.microsoft.com/library/bg182326%28v=vs.85%29?f=255&MSPPError=-2147217396   

Thanks
Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 2:30am

I am still not able to find a way to resolve this. Here is thestripped down version of the code. I have removed all unwanted code. Let me know how to solve this...

Create a list Foo with a date column "Due Date".Make title column non mandatory. Add this script in newform and editform.

<script src="/Style Library/jquery-1.11.2.min.js" type="text/javascript"></script>

<script type="text/javascript">

var context,oList,collListItem,id,filterValue,Url;

$(document).ready(function()
{

 Url=window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl

//Hookup save and redirection in NewForm
if(window.location.pathname.toLowerCase().indexOf("newform")!=-1)
  {
    SaveAndRedirectToEditForm();
  }
  else if(window.location.pathname.toLowerCase().indexOf("editform")!=-1)
  {
      SaveAndRedirectToAllItems();
  }
});

          
function SaveAndRedirectToAllItems()
{
  var button = $("input[id$=SaveItem]"); 
 button.removeAttr("onclick"); 

 button.click(function() { 
   
     context= new SP.ClientContext.get_current();
     oList = context.get_web().get_lists().getByTitle('Foo');
      id=getParameterByName("ID");
     if(id!="")
     {
       collListItem=oList.getItemById(id); 
       SetItems();
       
       context.executeQueryAsync(onSaveQuerySucceeded,onQueryFailed);
      }
   
  }); 
}



function SaveAndRedirectToEditForm()
{

 var button = $("input[id$=SaveItem]"); 
 button.removeAttr("onclick"); 

 button.click(function() { 

     context= new SP.ClientContext.get_current();
     oList = context.get_web().get_lists().getByTitle('Foo');

      var itemCreateInfo = new SP.ListItemCreationInformation();
      collListItem = oList.addItem(itemCreateInfo);
     SetItems();
    context.load(collListItem);
    context.executeQueryAsync(onSaveQuerySucceeded,onQueryFailed);

});

}



function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}




function SetItems()
{
        if($("input[Title^='Due Date']").val()!="")
         collListItem.set_item('DueDate',$("input[Title^='Due Date']").val());
       collListItem.update();
}








//Redirect usre to edit/display form
function onSaveQuerySucceeded() {
    if(window.location.pathname.toLowerCase().indexOf("newform")!=-1)
     window.location.href="/lists/Foo/EditForm.aspx?ID="+collListItem.get_id();
     else if(window.location.pathname.toLowerCase().indexOf("editform")!=-1)
     {
      var path="/lists/Foo/AllItems.aspx?View=%7B7677A2EB%2D9227%2D43EC%2D8C66%2DF732052795E3%7D&SelectedID="+id;            
      window.location.href=path;
      
     }  
}




    /* Displays error if request failed*/
 function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


</script>




  • Edited by sanjuv 43 minutes ago
May 28th, 2015 11:27pm

I am still not able to find a way to resolve this. Here is thestripped down version of the code. I have removed all unwanted code. Let me know how to solve this...

Create a list Foo with a date column "Due Date".Make title column non mandatory. Add this script in newform and editform.

<script src="/Style Library/jquery-1.11.2.min.js" type="text/javascript"></script>

<script type="text/javascript">

var context,oList,collListItem,id,filterValue,Url;

$(document).ready(function()
{

 Url=window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl

//Hookup save and redirection in NewForm
if(window.location.pathname.toLowerCase().indexOf("newform")!=-1)
  {
    SaveAndRedirectToEditForm();
  }
  else if(window.location.pathname.toLowerCase().indexOf("editform")!=-1)
  {
      SaveAndRedirectToAllItems();
  }
});

          
function SaveAndRedirectToAllItems()
{
  var button = $("input[id$=SaveItem]"); 
 button.removeAttr("onclick"); 

 button.click(function() { 
   
     context= new SP.ClientContext.get_current();
     oList = context.get_web().get_lists().getByTitle('Foo');
      id=getParameterByName("ID");
     if(id!="")
     {
       collListItem=oList.getItemById(id); 
       SetItems();
       
       context.executeQueryAsync(onSaveQuerySucceeded,onQueryFailed);
      }
   
  }); 
}



function SaveAndRedirectToEditForm()
{

 var button = $("input[id$=SaveItem]"); 
 button.removeAttr("onclick"); 

 button.click(function() { 

     context= new SP.ClientContext.get_current();
     oList = context.get_web().get_lists().getByTitle('Foo');

      var itemCreateInfo = new SP.ListItemCreationInformation();
      collListItem = oList.addItem(itemCreateInfo);
     SetItems();
    context.load(collListItem);
    context.executeQueryAsync(onSaveQuerySucceeded,onQueryFailed);

});

}



function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}




function SetItems()
{
        if($("input[Title^='Due Date']").val()!="")
         collListItem.set_item('DueDate',$("input[Title^='Due Date']").val());
       collListItem.update();
}








//Redirect usre to edit/display form
function onSaveQuerySucceeded() {
    if(window.location.pathname.toLowerCase().indexOf("newform")!=-1)
     window.location.href="/lists/Foo/EditForm.aspx?ID="+collListItem.get_id();
     else if(window.location.pathname.toLowerCase().indexOf("editform")!=-1)
     {
      var path="/lists/Foo/AllItems.aspx?View=%7B7677A2EB%2D9227%2D43EC%2D8C66%2DF732052795E3%7D&SelectedID="+id;            
      window.location.href=path;
      
     }  
}




    /* Displays error if request failed*/
 function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


</script>




  • Edited by sanjuv Friday, May 29, 2015 6:55 AM
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 3:26am

Just noticed that even without redirection, date is getting decremented...Is something wrong in the code?

//Redirect usre to edit/display form
function onSaveQuerySucceeded() {

alert(collListItem.get_item("DueDate"));
}


May 29th, 2015 11:47am

The behavior is the same even on office365. Any ideas how to resolve this?
Free Windows Admin Tool Kit Click here and download it now
June 2nd, 2015 2:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics