Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

New Post: Calling GetListItems then UpdateListItems from hyperlink

$
0
0
Matthew thank you for the guidance.

I had previously read that same discussion thread but I think I was lost in all the tangled xsl and conditional logic. I was overthinking it with nesting functions and you were right, it was simple! After fully understanding what the code in your link provided was doing I was able to come up with this working code which has separate functions:
$().SPServices({
    operation: "GetListItems",
    async: false,
    listUrl: "/Employee/Employees/Lists/Approved%20Announcements/",
    listName: "{ABE655C8-0B43-4421-B555-4B1748D9D1A3}",
    CAMLViewFields: "<ViewFields><FieldRef Name='Created' /><FieldRef Name='Author' /><FieldRef Name='AnnouncementType' /><FieldRef Name='Title' /><FieldRef Name='PublishDate' /><FieldRef Name='Expires' /><FieldRef Name='PromoteToBanner' /><FieldRef Name='UseBanner' /><FieldRef Name='BannerCaption' /><FieldRef Name='Modified' /><FieldRef Name='AnnouncementImage' /><FieldRef Name='ApprovalStatus' /><FieldRef Name='ID' /></ViewFields>",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='ApprovalStatus' /><Value Type='Choice'>Pending</Value></Eq></Where></Query>",     
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var created = $(this).attr("ows_Created");
        var createdby = $(this).attr("ows_Author").split(";#");
        var lastmodified = $(this).attr("ows_Modified");
        var type = $(this).attr("ows_AnnouncementType");
        var title = $(this).attr("ows_Title");
        var pubdate = $(this).attr("ows_PublishDate").split(" ");
        var expdate = $(this).attr("ows_Expires").split(" ");
        var promote = $(this).attr("ows_PromoteToBanner");
        var usebanner = $(this).attr("ows_UseBanner");
        var bannercap = $(this).attr("ows_BannerCaption");
        var appstatus = $(this).attr("ows_ApprovalStatus");
        var image = $(this).attr("ows_AnnouncementImage").split(",");
        var body = $(this).attr("ows_Body");
        var itemid = $(this).attr("ows_ID");
        
        var announcesubqueuerow = "<tr><td>"+created+"</td><td>"+createdby[1]+"</td><td>"+type+"</td><td>"+title+"</td><td>"+pubdate[0]+"</td><td>"+expdate[0]+"</td><td>"+promote+"</td><td>"+usebanner+"</td><td>"+bannercap+"</td><td>"+appstatus+"</td><td><a href='#' id='"+itemid+"' class='approvetoggle'>Approve</a></td></tr>";

        $("#queuecontainer table tbody").append(announcesubqueuerow);
        

        });
    }
});
$("#queuecontainer a").on("click", function (event) {
        event.preventDefault();
        var itemidupdate = $(this).attr("id");
                    
        $().SPServices({
            operation: "UpdateListItems",
            async: false,
            batchCmd: "Update",
            listName: "{ABE655C8-0B43-4421-B555-4B1748D9D1A3}",
            valuepairs: [["ApprovalStatus", "Approved"]],
            ID: itemidupdate,
            debug: false,
            completefunc: function(xData, Status) {
                alert("Announcement Approved");
            }
        });
}); 
I understand if I need more hyperlinks in other columns in the same table I will have to target the selector a bit better but this is good for now.

Thanks,
Dan

Viewing all articles
Browse latest Browse all 6517

Trending Articles



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