Quantcast
Viewing all articles
Browse latest Browse all 6517

New Post: AddView

Hi,

I don't know if this is of any help - and please forgive me if it isn't - but I managed to get AddView working fine, using this sample?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>  
 <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2013.01/jquery.SPServices-2013.01.min.js"></script>

<script type="text/javascript">
var divId = "#WSOutput";
var out = "";

// main function
$().ready(function () {

  $().SPServices({
    operation: 'AddView',
    async: false,
    webURL: '<URL of site - no trailing slash>',
    listName: 'Tasks',
    viewName: 'New View',  // docs state that a GUID is required, but a normal view name still works...
    viewFields: '<ViewFields><FieldRef Name="Title" /><FieldRef Name="ID" /></ViewFields>',
    rowLimit: '<RowLimit Paged="True">100</RowLimit>',
    type: 'HTML',
    makeViewDefault: true,
    completefunc: function (xData, Status) {
      $(divId).append("<b>This is the output from the AddView operation:</b><br>");
      $(xData.responseXML).SPFilterNode("AddViewResult").each(function() {
        $(this).SPFilterNode("View").each(function() {
        var theDisplayName = $(this).attr("DisplayName");
        var theDefaultView = $(this).attr("DefaultView");
        var thePersonalView = $(this).attr("Personal");

        if (Status ==  "success") {
          out = "View has been successfully added.<p>";
          out += "Details of view:" + "<br>" +
               "Display name of View: " + theDisplayName + "<br>" +
               "Is it a default view? " + theDefaultView + "<br>" +
               "Is it a personal view? " + thePersonalView + "<br>" +

                 "<hr>";

        } else if (Status == "error") {
          if(strError != "") {          
            out = "Error: " + strError + "<hr>";
          }
        }
      });
     });
     $(divId).append(out);  
    }
  });
});
The only differences I could see between my code and both examples given here, is that:
1) I'm not using a GUID for the viewName (whereas I know the OP's sample did)
2) I'm specifying webURL, which wasn't specified in your code, Marc

The above was originally tested on SP2007, using jQuery 1.7.2 and SPServices 0.71 - I've updated it to 2013 version of SPServices, and jQuery 1.8.2; in both cases I couldn't see any problem. I should point out that it did increment a number on the end of the URL, for each instance of the "New View" set up, but otherwise it produced a series of views for me, with no issue?

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>