I coded some Javascript that will retrieve the GUID value of a SharePoint list and the first item ID of that list.
Once all the values have been determined, Javascript will open the Infopath form of that list using the
SharePoint Client Side Dialog object.
<script type="text/javascript">
function OpenDialogOki() {
var options = SP.UI.$create_DialogOptions();
options.resizable = 1;
options.scroll = 1;
clientContext = new SP.ClientContext.get_current();
spWebobj = this.clientContext.get_web();
spListobj = spWebobj.get_lists().getByTitle("MessagefromOki");
var spCamlQuery = new SP.CamlQuery();
var spViewXML = '<View><Query /></View>';
spCamlQuery.set_viewXml(spViewXML);
spListobjItems = spListobj.getItems(spCamlQuery);
clientContext.load(spWebobj);
clientContext.load(spListobjItems);
this.collList = spWebobj.get_lists();
clientContext.load(collList, 'Include(Title, Id)');
// get the GUID info
var listInfo = '';
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
if ( oList.get_title() == "MessageFromOki") {
listInfo += 'Title: ' + oList.get_title() + ' ID: '
+ oList.get_id().toString() + '\n';
var oki_guid = oList.get_id().toString();
}
}
//window.OkiItemID - global variable of the list item ID
options.url = "/Lists/MessageFromOki/Item/displayifs.aspx?List="
+ oki_guid + "&ID=" + window.OkiItemID;
SP.UI.ModalDialog.showModalDialog(options);
}
function OpenDialogSal() {
var options = SP.UI.$create_DialogOptions();
options.resizable = 1;
options.scroll = 1;
clientContext = new SP.ClientContext.get_current();
spWebobj = this.clientContext.get_web();
spListobj = spWebobj.get_lists().getByTitle("MessagefromSal");
var spCamlQuery = new SP.CamlQuery();
var spViewXML = '<View><Query /></View>';
spCamlQuery.set_viewXml(spViewXML);
spListobjItems = spListobj.getItems(spCamlQuery);
clientContext.load(spWebobj);
clientContext.load(spListobjItems);
this.collList = spWebobj.get_lists();
clientContext.load(collList, 'Include(Title, Id)');
// get the GUID info
var listInfo = '';
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
if ( oList.get_title() == "MessageFromSal") {
listInfo += 'Title: ' + oList.get_title() + ' ID: ' + oList.get_id().toString() + '\n';
var sal_guid = oList.get_id().toString();
}
}
options.url = "/_layouts/listform.aspx?PageType=4&ListId=" + sal_guid + "&ID=" + window.SalItemID;
SP.UI.ModalDialog.showModalDialog(options);
}
var tpj = jQuery;
tpj.noConflict();
tpj(document).ready(function () {
if (typeof(_spBodyOnLoadWrapper) != 'undefined') {
_spBodyOnLoadWrapper();
}
if (tpj.fn.cssOriginal != undefined)
tpj.fn.css = tpj.fn.cssOriginal;
tpj('#services-example-1').services(
{
width: 920,
height: 300,
slideAmount: 5,
slideSpacing: 30,
carousel: "off",
touchenabled: "on",
mouseWheel: "on",
hoverAlpha: "off",
// Turns Alpha Fade on/off by Hovering
slideshow: 0,
// 0 = No SlideShow, 1000 = 1 sec Slideshow
(rotating automatically)
hovereffect: "on",
// All Hovereffect on/off
callBack: function () { }
//Callback any Function after loaded
});
});
ExecuteOrDelayUntilScriptLoaded(getOkiTitle, "sp.js");
function getOkiTitle() {
clientContext = new SP.ClientContext.get_current();
spWebobj = this.clientContext.get_web();
spListobj = spWebobj.get_lists().getByTitle("MessagefromOki");
var spCamlQuery = new SP.CamlQuery();
var spViewXML = '<View><Query /></View>';
spCamlQuery.set_viewXml(spViewXML);
spListobjItems = spListobj.getItems(spCamlQuery);
clientContext.load(spWebobj);
clientContext.load(spListobjItems);
// need to retrieve GUID for List MessageFromSal, MessageFromOki
this.collList = spWebobj.get_lists();
clientContext.load(collList, 'Include(Title, Id)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
clientContext.executeQueryAsync(onSuccess, onFail);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function GetSalTitle() {
clientContext = new SP.ClientContext.get_current();
spWebobj = this.clientContext.get_web();
spListobj = spWebobj.get_lists().getByTitle("MessagefromSal");
var spCamlQuery = new SP.CamlQuery();
var spViewXML = '<View><Query /></View>';
spCamlQuery.set_viewXml(spViewXML);
spListobjItems = spListobj.getItems(spCamlQuery);
clientContext.load(spWebobj);
clientContext.load(spListobjItems);
clientContext.executeQueryAsync(onSuccess2, onFail);
}
function onSuccess2() {
liCount = spListobjItems.get_count();
//alert (liCount);
for (x = 0; x < liCount; x++) {
var listItem = spListobjItems.itemAt(x);
var itemTitle = listItem.get_item('Title');
var SalItemID = listItem.get_id();
//window.SalItemID = SalItemID;
//display dynamic title on the page
document.getElementById("SaloTitle").innerHTML = itemTitle;
window.SalItemID = SalItemID;
}
function onSuccess() {
// get the GUID value of MessageFromOki list
liCount = spListobjItems.get_count();
for (x = 0; x < liCount; x++) {
var listItem = spListobjItems.itemAt(x);
var itemTitle = listItem.get_item('Title');
var OkiItemID = listItem.get_id();
//display dynamic title on the page
document.getElementById("OkiTitle").innerHTML = itemTitle;
}
// global variable of the list item to display
window.OkiItemID = OkiItemID;
GetSalTitle()
}
function onFail() {
alert('request failed ' + args.get_message() + '\n'
+ args.get_stackTrace());
}
</script>
Once all the values have been determined, Javascript will open the Infopath form of that list using the
SharePoint Client Side Dialog object.
<script type="text/javascript">
function OpenDialogOki() {
var options = SP.UI.$create_DialogOptions();
options.resizable = 1;
options.scroll = 1;
clientContext = new SP.ClientContext.get_current();
spWebobj = this.clientContext.get_web();
spListobj = spWebobj.get_lists().getByTitle("MessagefromOki");
var spCamlQuery = new SP.CamlQuery();
var spViewXML = '<View><Query /></View>';
spCamlQuery.set_viewXml(spViewXML);
spListobjItems = spListobj.getItems(spCamlQuery);
clientContext.load(spWebobj);
clientContext.load(spListobjItems);
this.collList = spWebobj.get_lists();
clientContext.load(collList, 'Include(Title, Id)');
// get the GUID info
var listInfo = '';
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
if ( oList.get_title() == "MessageFromOki") {
listInfo += 'Title: ' + oList.get_title() + ' ID: '
+ oList.get_id().toString() + '\n';
var oki_guid = oList.get_id().toString();
}
}
//window.OkiItemID - global variable of the list item ID
options.url = "/Lists/MessageFromOki/Item/displayifs.aspx?List="
+ oki_guid + "&ID=" + window.OkiItemID;
SP.UI.ModalDialog.showModalDialog(options);
}
function OpenDialogSal() {
var options = SP.UI.$create_DialogOptions();
options.resizable = 1;
options.scroll = 1;
clientContext = new SP.ClientContext.get_current();
spWebobj = this.clientContext.get_web();
spListobj = spWebobj.get_lists().getByTitle("MessagefromSal");
var spCamlQuery = new SP.CamlQuery();
var spViewXML = '<View><Query /></View>';
spCamlQuery.set_viewXml(spViewXML);
spListobjItems = spListobj.getItems(spCamlQuery);
clientContext.load(spWebobj);
clientContext.load(spListobjItems);
this.collList = spWebobj.get_lists();
clientContext.load(collList, 'Include(Title, Id)');
// get the GUID info
var listInfo = '';
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
if ( oList.get_title() == "MessageFromSal") {
listInfo += 'Title: ' + oList.get_title() + ' ID: ' + oList.get_id().toString() + '\n';
var sal_guid = oList.get_id().toString();
}
}
options.url = "/_layouts/listform.aspx?PageType=4&ListId=" + sal_guid + "&ID=" + window.SalItemID;
SP.UI.ModalDialog.showModalDialog(options);
}
var tpj = jQuery;
tpj.noConflict();
tpj(document).ready(function () {
if (typeof(_spBodyOnLoadWrapper) != 'undefined') {
_spBodyOnLoadWrapper();
}
if (tpj.fn.cssOriginal != undefined)
tpj.fn.css = tpj.fn.cssOriginal;
tpj('#services-example-1').services(
{
width: 920,
height: 300,
slideAmount: 5,
slideSpacing: 30,
carousel: "off",
touchenabled: "on",
mouseWheel: "on",
hoverAlpha: "off",
// Turns Alpha Fade on/off by Hovering
slideshow: 0,
// 0 = No SlideShow, 1000 = 1 sec Slideshow
(rotating automatically)
hovereffect: "on",
// All Hovereffect on/off
callBack: function () { }
//Callback any Function after loaded
});
});
ExecuteOrDelayUntilScriptLoaded(getOkiTitle, "sp.js");
function getOkiTitle() {
clientContext = new SP.ClientContext.get_current();
spWebobj = this.clientContext.get_web();
spListobj = spWebobj.get_lists().getByTitle("MessagefromOki");
var spCamlQuery = new SP.CamlQuery();
var spViewXML = '<View><Query /></View>';
spCamlQuery.set_viewXml(spViewXML);
spListobjItems = spListobj.getItems(spCamlQuery);
clientContext.load(spWebobj);
clientContext.load(spListobjItems);
// need to retrieve GUID for List MessageFromSal, MessageFromOki
this.collList = spWebobj.get_lists();
clientContext.load(collList, 'Include(Title, Id)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
clientContext.executeQueryAsync(onSuccess, onFail);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function GetSalTitle() {
clientContext = new SP.ClientContext.get_current();
spWebobj = this.clientContext.get_web();
spListobj = spWebobj.get_lists().getByTitle("MessagefromSal");
var spCamlQuery = new SP.CamlQuery();
var spViewXML = '<View><Query /></View>';
spCamlQuery.set_viewXml(spViewXML);
spListobjItems = spListobj.getItems(spCamlQuery);
clientContext.load(spWebobj);
clientContext.load(spListobjItems);
clientContext.executeQueryAsync(onSuccess2, onFail);
}
function onSuccess2() {
liCount = spListobjItems.get_count();
//alert (liCount);
for (x = 0; x < liCount; x++) {
var listItem = spListobjItems.itemAt(x);
var itemTitle = listItem.get_item('Title');
var SalItemID = listItem.get_id();
//window.SalItemID = SalItemID;
//display dynamic title on the page
document.getElementById("SaloTitle").innerHTML = itemTitle;
window.SalItemID = SalItemID;
}
function onSuccess() {
// get the GUID value of MessageFromOki list
liCount = spListobjItems.get_count();
for (x = 0; x < liCount; x++) {
var listItem = spListobjItems.itemAt(x);
var itemTitle = listItem.get_item('Title');
var OkiItemID = listItem.get_id();
//display dynamic title on the page
document.getElementById("OkiTitle").innerHTML = itemTitle;
}
// global variable of the list item to display
window.OkiItemID = OkiItemID;
GetSalTitle()
}
function onFail() {
alert('request failed ' + args.get_message() + '\n'
+ args.get_stackTrace());
}
</script>
No comments:
Post a Comment