0

Is there a possibility to create a URL to a list/library with a certain view but not using on the .aspx in the URL but the GUID of that view?

So not:

 https://company.com/sites/DocLib/Forms/View1.aspx

but something like:

https://company.com/sites/DocLib/Forms/whatwever.aspx?View={16E9F3B1-7950-4A3C-A18A-8E6FBE91B9A8}

Thanks

1

You can add this custom js code to the page.
It gets the ViewID and listName from the URL, fetches all the view for that list and redirect to the page the with given Guid.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}


var viewID = getParameterByName("ViewId");
var listName = getParameterByName("ListName");
//var viewID="2c45ea14-acza-4b4e-8855e-3b751b354a5c";
//var listName="TestList;

var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/" +
        "getByTitle('"+listName+"')/Views";
var requestHeaders = { "accept": "application/json;odata=verbose" };
$.ajax({
    url: requestUri,
    async: false,
    contentType: "application/json;odata=verbose",
    headers: requestHeaders,
    success: function (data) {
        console.log(data);

        $(data.d.results).each(function (index) {
            console.log(data.d.results[index].Id)
            if (data.d.results[index].Id==viewID){
                var newUrl=data.d.results[index].ServerRelativeUrl;
                if (!(window.location.indexOf(newUrl)>-1)){
                    window.location=newUrl;
                }
            }
        });
    },
    error: function (msg) {
        console.log(msg.responseText);
    }
});

</script>

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.