2011-02-14 86 views
0

我有一个名为Projects的Sharepoint列表和另一个名为Tasks的列表。 “任务”列表对项目列表的标题具有查找字段,以便我可以使用“插入相关列表”选项。插入相关列表后,选择项目将只显示与该项目相关的任务。
如何在添加新任务时将任务列表默认为当前选定项目的项目查找值?默认的新子项列表项到选定的父列表项

+0

你怎么定义的 “当前所选项目”?通过网址,查询字符串? – djeeg 2011-02-15 06:42:51

回答

1

基于Corey Martins related lists prefill scripts我能够让项目自动选择列表。我修改了脚本以添加一些附加功能:

- 现在使用弹出的新项目对话框而不是切换到新项目页面。
- 现在可以使用公告列表和文档库(文档库需要将JavaScript添加到编辑表单中,而不是新的表单)。
- 将填充SelectedID URL参数,这是在列表第一次加载时不会发生的。

这里是我修改过的脚本:
RLHelper-ParentDisplayForm.js

/* 
SharePoint 2010 Related List Prefill Version 1.2 
Call JQuery and this file from the parent list's view item page that contains related list web parts. 
Instructions: http://code.google.com/p/sp2010-related-list-prefill/ 
RLHelper-ParentDisplayForm.js 
*/ 
function getQuerystring(ji) { 
    hu = window.location.search.substring(1); 
    gy = hu.split("&"); 
    for (i=0;i<gy.length;i++) { 
     ft = gy[i].split("="); 
     if (ft[0] == ji) { 
      return ft[1]; 
     } 
    } 
} 

_spBodyOnLoadFunctionNames.push("updateSelection"); 
function updateSelection() { 
    var selId = getQuerystring("SelectedID"); 
    if (isNaN(selId) === true) { 
     SelectField('VIEW GUID GOES HERE','1'); 
    } 
    return false; 
} 

RLHelper-ChildNewForm.js

/* 
SharePoint 2010 Related List Pre-fill Version 1.2 
Call JQuery and this file from the child list's new item page. 
Instructions: http://code.google.com/p/sp2010-related-list-prefill/ 

RLHelper-ChildNewForm.js 
*/ 
function getQuerystring(ji, fromParent) { 
    var hu; 
    if(fromParent){ 
     hu = parent.window.location.search.substring(1); 
    } 
    else{ 
     hu = window.location.search.substring(1); 
    } 
    var gy = hu.split("&"); 
    var i = 0; 
    for (i=0;i<gy.length;i++) { 
     var ft = gy[i].split("="); 
     if (ft[0] === ji) { 
      return ft[1]; 
     } 
    } 
} 

function fillfromParent(childfield) { 
    var dlg = getQuerystring("IsDlg", false); 
    if (isNaN(dlg) === false && dlg == 1) { 
     var SelId = getQuerystring("SelectedID", true); 
     var parentid = SelId.match(/\d+$/); 
     if (isNaN(parentid) === false && parentid > 0) { 
      $("select[title="+childfield+"]").val(parentid); 
     } 
    } 
}