I recently figured out how to get 5 different documents loaded into tabs as iframes.. or at least I got one of them to work. Example:
The others are blank for some reason, but still take up the same size in the tab:
Each of the tabs is just a content editor running the following script:
<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 ProjectCharter = '';
//var ActionPlan = '';
//var MonthlyReport = '';
//var ProjectSchedule = '';
var Budget = '';
var listItemEnumerator = collListitem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
//ProjectCharter += oListItem.get_item('Project_x0020_Charter');
//ActionPlan += oListItem.get_item('Action_x0020_Plan');
//MonthlyReport += oListItem.get_item('Monthly_x0020_Report');
//ProjectSchedule += oListItem.get_item('Project_x0020_Schedule');
Budget += oListItem.get_item('Project_x0020_Budget');
};
var docUrl= Budget;//set the doclibname to the pulled field
modIframe(docUrl);
}
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>
All I changed between the 5 was uncommenting/recommenting the variables, then fixing the docUrl. This script pulls from the following list depending on the parameter passed. The parameter I use is projectName, where it can be equal to PROJ1, PROJ2, or PROJ3 (acting as a project code of sorts).
The list has the parameters in the title column, and then has 5 text columns in which the following workflow fills based on the contents of the document library:
The workflow looks like such (it just updates the projectParameters list with URLs for the iframe):
I cannot for the life of me figure out why only one of the scripts is working. I tested all of the links in ProjectParameters, and they are each valid/ working. It looks like the onQuerySucceeded method isn't getting run for some reason, as I determined using the dev tools (a console.log command inside onQuerySucceeded didn't get ran).
Update, I tested the following .aspx page created from Sharepoint designer(this won't turn into a code block I'm sorry):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="C#" %> <%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
Test
$(document).ready(function(){ var scriptbase = "https://projectadvocatesllc.sharepoint.com/sites/project_sb1" + "/_layouts/15/"; //Do not change the order, scripts should load by order. $.getScript(scriptbase + "init.js", function () { $.getScript(scriptbase + "SP.Runtime.js", function () { $.getScript(scriptbase + "SP.js", retrieveListItems); }); }); }); function retrieveListItems() { 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('' + '' + parameter + '' + '10'); //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, Include('Project_x0020_Schedule'));//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 ProjectSchedule = ''; var listItemEnumerator = collListitem.getEnumerator(); while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); ProjectSchedule += oListItem.get_item('Project_x0020_Schedule'); }; var docUrl= ProjectSchedule;//set the doclibname to the pulled field modIframe(docUrl); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } function modIframe(DocumentLibraryUrl){ document.getElementById('doclibView').src=DocumentLibraryUrl; }