Sunday, November 23, 2014

JavaScript to Access List Item GUID in SharePoint 2010

The SharePoint 2010 client object model has provided JavaScript means to access SharePoint Lists, Libraries and items, etc.... Below is a sample where I access a SharePoint list item GUID information during a on click event on a list item. The item click is triggered at the XSLT code rendering the custom field. This is the related JavaScript.

Here the item GUID is captured.



var itemID = null;
var item = null;
var currentItemGUID = null;

//Assigned the itemID value coming from XSLT [JavaScript method call on a hyperlinks OnClick() method]

function MyTestFunction() {
    context = new SP.ClientContext.get_current();
     list = context.get_web().get_lists().getById(SP.ListOperation.Selection.getSelectedList());
     item = list.getItemById(itemID);

    context.load(item);
    context.executeQueryAsync(
        function(sender, args) {
            currentItemGUID = item.get_item('UniqueId');
        },
        function(sender, args) {
            alert('Request Failed' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
        }, "sp.js");
    
}

No comments:

Post a Comment