1

we have a bunch of site collections dedicated to making project management sites. The newest site I set up works flawless except for some code I custom made.

The view I am trying to accomplish (and I did) is below:

enter image description here

That example is from a separate site collection. So, on to how it works. The header "Project management" is the title of the content editor that is referencing HillbillyTabs in siteAssets. The webpart titled "Project documents" is a content editor referencing custom javascript. Basically what the javascript does is it takes the current URL, breaks it down, extracts the correct name for a document library based on the parameter in the URL (projectName=x). Once the JS has the correct URL for the doclib to be displayed, it then modifies the HTML of the iFrame and adds the document library as the source.

On the Newest site collection, I notice two things that are different... First, the iFrame doesn't display: enter image description here

Second, the URL is being weird. When I click on the link to the current page it uses URL: /sites/countryside/SitePages/Project%20Dashboard.aspx?ProjectName=CS2

However, once the page is loaded the URL changes to:

/sites/countryside/SitePages/Project%20Dashboard.aspx?ProjectName=CS2#InplviewHashac1b15bc-ad6c-4fb0-9901-0983852b4bb0=-CascDelWarnMessage%3D1-FilterField1%3DProjectName-FilterValue1%3DCS2-ShowInGrid%3DTrue

Here is the Js code I used...

    <html>
<head>
    <script type="text/javascript">
        ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");

        function retrieveListItems() {
            //retrieve the document library's name
            var parameter = GetUrlKeyValue('ProjectName'); //get the parameter name, tested and it works

            var clientContext = new SP.ClientContext(); //create client context at this site collection.
            var oList = clientContext.get_web().get_lists().getByTitle('ProjectParameters'); //create list object by the title of the, projectParameters is the list to look through
            var camlQuery = new SP.CamlQuery(); //create CAMLquery to pull in list items.
            camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'LinkTitle\'/>' + 
            '<Value Type=\'Computed\'>' + parameter + '</Value></Eq></Where></Query></View>' + 
            '<RowLimit>10</RowLimit></View>'); //define the query, here we pull in the field where the parameter matches. 
            this.collListitem = oList.getItems(camlQuery);//get the items from the list object based on the query defined above.

            clientContext.load(collListitem);//telling the object model to prepare to execute the following object by loading it into the client context.

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));  


        }
        function onQuerySucceeded(sender, args) {
            var listItemInfo = '';
            var listItemEnumerator = collListitem.getEnumerator();

            while (listItemEnumerator.moveNext()) {
                var oListItem = listItemEnumerator.get_current();
                listItemInfo += oListItem.get_item('docLibName');//ih3c is the internal name for the text column that contains doclib names
            };
            var docLibName= listItemInfo;//set the doclibname to the pulled field

            //break apart the url
            var pathArray = window.location.pathname.split( '/' );
            var firstLevelLocation = pathArray[1];
            var secondLevelLocation = pathArray[2];

            var viewUrl = '/Forms/AllItems.aspx?IsDlg=1';//IsDlg=1 strips down the navigation

            //put the docliburl back together
            var docLibUrl = window.location.protocol+ "//" + window.location.host + "/" + firstLevelLocation + "/" + secondLevelLocation + "/" + docLibName + viewUrl;
            alert(docLibUrl)
            //add the docliburl to the iframe's src attribute
            modIframe(docLibUrl);
        }

        function onQueryFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }
        function modIframe(DocumentLibraryUrl){
            document.getElementById('doclibView').src=DocumentLibraryUrl;
        }

    </script>
</head>
<body>
    <iframe src='' height=600 width=900 id='doclibView'>
    </iframe>
</body>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.