SharePoint 2013 - Get Item Url by REST API and Ajax

Hey,

This time I will present code to get client-side item

var urlRequest = RoiGetItemUrl(item, listName, rootUrl);
                    urlRequest.done(function (data, textStatus, jqXHR) {
                        var path = "";
                        jQuery.each(data.d.results, function (i, result) {
                            path = result.EncodedAbsUrl;
                        });
                        console.log("Item path is " + path);
                    });
                    urlRequest.fail(function (jqXHR, textStatus, errorThrown) {
                        RoiFailHandler(jqXHR, textStatus, errorThrown, state, fileUploadFailMessage);
                    });



// Return the link item url
function RoiGetItemUrl(item, listName, rootUrl)
{
    var call = jQuery.ajax({
        url: rootUrl + "/_api/Web/Lists/getByTitle('" + listName + "')/Items?$select=EncodedAbsUrl&$filter=Id eq " + item.Id,
        type: "GET",
        dataType: "json",
        headers: {
            Accept: "application/json;odata=verbose"
        }
    });
    return call;
}
// Handler with error event
function RoiFailHandler(jqXHR, textStatus, errorThrown, state, fileUploadFailMessage) {
    try {
        var response = JSON.parse(jqXHR.responseText);
        var message = response ? response.error.message.value : textStatus;
        console.log("Call failed. Error " + message);
    }
    catch (e) {
        console.log("Error " + e.message);
    }
   

}

Yours,
Roi

Comments

Popular posts from this blog

A sharepoint list view of the current month

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

Export SharePoint 2010 List to Excel with PowerShell