Javascript 允许在SharePoint NewForm.aspx中保存新项目并继续
Short:如何使默认SharePoint NewForm.aspx添加一个项目并停留在输入页面上,而不是返回列表视图所有项目?Javascript 允许在SharePoint NewForm.aspx中保存新项目并继续,javascript,sharepoint,sharepoint-2013,Javascript,Sharepoint,Sharepoint 2013,Short:如何使默认SharePoint NewForm.aspx添加一个项目并停留在输入页面上,而不是返回列表视图所有项目? 长: 我被要求允许SharePoint用户在SharePoint列表中输入许多新项目,而无需在每次保存时返回AllItems。 这一要求适用于许多列表,因此我不想为每种可能的内容类型开发特定的代码。 我想我可以编写一个简短的js文件,并在用户希望保存和继续时使用它。 到目前为止,我尝试在内容编辑器Web部件(CEWP)中添加“保存并继续”行为 我的第一种方法是更改S
长:
我被要求允许SharePoint用户在SharePoint列表中输入许多新项目,而无需在每次保存时返回AllItems。
这一要求适用于许多列表,因此我不想为每种可能的内容类型开发特定的代码。
我想我可以编写一个简短的js文件,并在用户希望保存和继续时使用它。
到目前为止,我尝试在内容编辑器Web部件(CEWP)中添加“保存并继续”行为 我的第一种方法是更改Source=参数,但没有成功(取消也返回到新源,或者在preSaveAction()中设置时忽略源)。
然后我尝试在preSaveAction中设置窗体操作:
<script type="text/javascript">
JSRequest.EnsureSetup();
var src = JSRequest.QueryString["Source"];
var exit = JSRequest.QueryString["exit"];
var isDialog = JSRequest.QueryString["IsDlg"];
var dlgParam = "";
if (isDialog)
dlgParam = "&IsDlg="+isDialog;
//If exit is defined its keeping default source parameter
if (exit) {
document.forms.aspnetForm.action= location.pathname+"?Source="+exit+dlgParam;
}
function PreSaveAction(){
//before saving the original source is saved in exit
exit=JSRequest.QueryString["Source"];
src=escapeProperly(window.location.protocol + '//' + window.location.host + _spPageContextInfo.serverRequestPath);
document.forms.aspnetForm.action=location.pathname+"?Source="+src+"&exit="+exit+dlgParam;
return true;
JSRequest.EnsureSetup();
var src=JSRequest.QueryString[“Source”];
var exit=JSRequest.QueryString[“exit”];
var isDialog=JSRequest.QueryString[“IsDlg”];
var dlgParam=“”;
if(isDialog)
dlgParam=“&IsDlg=“+isDialog;
//如果定义了exit,则保留默认的源参数
如果(退出){
document.forms.aspnetForm.action=location.pathname+“?Source=“+exit+dlgParam;
}
函数PreSaveAction(){
//保存之前,原始源将保存在“退出”中
exit=JSRequest.QueryString[“Source”];
src=escapeProperty(window.location.protocol+'/'+window.location.host+\u spPageContextInfo.serverRequestPath);
document.forms.aspnetForm.action=location.pathname+“?Source=“+src+”&exit=“+exit+dlgParam;
返回true;
操作按预期更新,但在保存新项目时,用户仍会重定向到AllItems.aspx
另一个尝试是添加一个特定的按钮,重用功能区和页面按钮中使用的SharePoint javascript操作
<script type="text/javascript">
function adressePage() {
return window.location.protocol + '//' + window.location.host + _spPageContextInfo.serverRequestPath;
}
function saveContinue() {
document.getElementById("cmdSaveContinue").disabled=true;
if (!PreSaveItem()) return false;
if (SPClientForms.ClientFormManager.SubmitClientForm("WPQ2")) {
SP.UI.Notify.addNotification("Saving ...", false);
window.location = adressePage();
} else {
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("cmdSaveContinue", "", true, "", adressePage(), false, true));
}
document.getElementById("cmdSaveContinue").disabled=false;
}
</script>
<input id="cmdSaveContinue" onclick="javascript:return saveContinue();" type="button" value="Enregistrer et continuer" style="top: -5.5em; position: relative;"/>
函数地址页(){
返回window.location.protocol+'/'+window.location.host+\u spPageContextInfo.serverRequestPath;
}
函数saveContinue(){
document.getElementById(“cmdSaveContinue”).disabled=true;
如果(!PreSaveItem())返回false;
if(SPClientForms.ClientFormManager.SubmitClientForm(“WPQ2”)){
SP.UI.Notify.addNotification(“保存…”,false);
window.location=adressePage();
}否则{
WebForm_DoPostBackWithOptions(新的WebForm_PostBackOptions(“cmdSaveContinue”,“true”,“adressePage(),false,true));
}
document.getElementById(“cmdSaveContinue”).disabled=false;
}
这样,将处理表单验证并保存项目。如果返回错误消息,表单将保留在NewItem上,但在执行
窗口后,错误消息将丢失。location=…
。当一切正常时,将保存该项目,用户将使用新的空NewForm.aspx。
但是SharePoint
SPClientForms.ClientFormManager.SubmitClientForm(“WPQ2”)
是异步执行的,有时(并非总是)重定向到
AllItems在我的重定向结束后出现。我被困在这一点上,害怕每次添加列表时,都会被迫编辑SPDesigner中的每个新表单页面。。。
信息:SharePoint server 2013内部部署,SPDesigner可能您可以通过InfoPath执行此操作,如果您有SP on prem和SPDesigner访问权限,您应该可以使用InfoPath。如果您转到InfoPath并自定义表单,则可以在提交>新表单后转到数据>提交选项>(高级>)>
您可以使用google“InfoPath Save and New”或转到Microsoft站点并查看演练。他们的演练建议使用两个按钮,一个打开新表单,另一个关闭表单。创建自定义的NewForm.aspx并添加新按钮,并在重定向中提及{}
<input type="button" class="contact-button" value="Submit and Create New Request" name="btnSaven" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={}')}" />
将脚本编辑器web部件添加到视图中
<input type="button" value="Add items in continuity" onclick="openNewItemDialog()"/>
<script>
function openNewItemDialog() {
var options = {
url: 'http://sp/sites/dev/Lists/<yourList>/NewForm.aspx',
dialogReturnValueCallback: function(result, returnValue) {
if(result== SP.UI.DialogResult.OK)
{
openNewItemDialog()
}
}
}
SP.UI.ModalDialog.showModalDialog(options);
}
函数openNewItemDialog(){
变量选项={
网址:'http://sp/sites/dev/Lists//NewForm.aspx',
dialogReturnValueCallback:函数(结果,returnValue){
if(result==SP.UI.DialogResult.OK)
{
openNewItemDialog()
}
}
}
SP.UI.ModalDialog.showModalDialog(选项);
}
必须编辑每一个带有已停产产品的新表单将涉及大量工作。我将花更少的时间向用户解释这是不可能的。不过,感谢您的建议。