1

I found some code on line, see below, and changed it to meet my needs but when I run it I get:

Due Date undefined

This is the only value in the list, but it should look like:

Due Date 01/31/2019

Below is the code. Also I'm not a coder, so if you answer please show me what to correct.

<table width="70%" align="left" id="myHTMLTable" border="1"> 
   <tbody>
      <tr align="left"> 
         <td>
            <b>DueDate</b></td> 
      </tr>
      <tr align="middle"> 
         <td align="left">undefined</td> 
      </tr> 
   </tbody>
</table> 
<script type="text/javascript">

getMyListData() ;

function getMyListData()
{                     
        var method = "GetListItems";                 
        var webURL =  $().SPServices.SPGetCurrentSite() ;                     
        var list = "Project Statement";                      
        var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>";
        var query = "<Query><OrderBy><FieldRef Name='Due-Date' /></OrderBy></Query>"; 


        $().SPServices
        ({
                    operation: method,
                    async: false, 
                    webURL: webURL,
                    listName: list,
                    CAMLViewFields: "<ViewFields Properties='True' />",
                    CAMLQuery: query,                                                                                     
                    completefunc: function (xData, Status)
                     {
                         $(xData.responseXML).SPFilterNode("z:row").each(function() 
                         {
                              var vDueDate = $(this).attr("ows_Due-Date");

                              $("#myHTMLTable").append("<tr align='middle'>" +
                               "<td align='left'>"+vDueDate+"</td>" + 
                           "</tr>");
                           });
                   }
       });
       };

      </script>
1

Make sure that you are using the internal field name correctly for the "Due Date" column.

I think it's not Due-Date so you got

an undefined error


To get the internal field name

  • Open list settings.
  • Below COlumns, Click on the column name.
  • Look at the URL, and check the Field Query String value.

    Ex:  &Field=Due_x0020_Date
    
  • In this case, the field internal name is Due_x0020_Date

Finally, in your code, update each Due Date occurrences with this internal field

var query = "<Query><OrderBy><FieldRef Name='Due_x0020_Date' /></OrderBy></Query>"; 

Also, I suggest using the U2U tool to get the internal name and build your CAML query in a correct manner

  • Got the date, but it looks like 2019-01-31 00:00:00. How do I change the format to look like: 31 January 2019? I've tried a few different formatting options that I found on line, but when I run them the date then does not show at all. – drcoz Nov 16 '18 at 14:38
  • Please close this question first by marking the answer as accepted, then ask this new question in independent question! Thanks! – Mohamed El-Qassas MVP Nov 16 '18 at 15:30

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.