使用Content editor webpart 为NewForm增加默认值
我现在的SharePoint,有一个Request审批的功能,在这个Request审批的过程中,要用到Discussion Board让审判者和发起人进行互动。在Request Page上一个Create Question link,当click 这个link ,会弹出SharePoint Discussion Board默认的NewForm.aspx,在NewForm.aspx URL里面会附加Request ID。
在NewForm.aspx里面插入Content Edit webpart,自带获取URL Request ID的值,并把它显示在Discussion Board对于的Request ID field上。这样当新的question 保存的时候,Request ID的值也已经保存了,就建立了Request 和 Discussion Board之间的联系!
使用SharePoint desinger 打开NewForm.aspx 并插入Content Editor Webpart. 在Content Editor Webpart插入下面的javascript.
<script type="text/javascript">
//获取NewForm.aspx上面存储Request ID的Text box client ID
var obj = document.getElementById("ctl00_m_g_6435b13f_22bf_41f3_b7f9_469f00cbfb2c_ctl00_ctl05_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00_TextField");
if (obj != null) {
// 获取URL Request ID的值并附给Text box
var frank_param = getParam('ARID');
if (frank_param != null) {
obj.value = frank_param.toString();
obj.readOnly = true;
}
}
function getParam(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
</script>