Hiya Plumsail
We have a form that is in a large panel:
But we are doing a redirect on the new form to a custom edit form that creates some extra related items in another list on save of the item. But the redirect doesn't work if the form is in a panel.
The redirect does work when the form is not in a panel.
Is there some extra Javacript I need to get the panel form to redirect on save or is it not possible?
Regards
Hello @Jamal_Smith-Graham,
Yes, the default redirection doesn't work in a panel. Please try out the below code to redirect user from New to Edit form when the form is opened in the panel.
fd.spSaved(function(result) {
var listId = fd.spFormCtx.ListAttributes.Id;
var itemId = result.Id;
if (fd.isPanel) {
const formCommands = new window.Plumsail.FormCommands({
webUrl: fd._formManager._webUrl,
listId: listId,
listUrl: fd._formManager._listUrl,
culture: _spPageContextInfo.currentUICultureName,
language: _spPageContextInfo.currentLanguage,
componentLoader: window._spComponentLoader
});
formCommands.load().then(function() {
formCommands._openPanel({
itemId: itemId,
contentTypeId: fd.contentTypeId,
formType: "Edit",
rootFolder: fd.rootFolder
});
});
} else {
//replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
result.RedirectUrl = "https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=6&ListId=" + listId + "&ID=" + itemId;
}
});
1 Like
thanks for this @mnikitina, the form is a different form set edit form, this looks like it would redirect to the default edit form is there a way I can redirect to another form set's edit form?
5ada64aa-37c6-4f53-b737-1603f1b37aeb is for form set ID
Hello @Jamal_Smith-Graham,
You can set up the custom routing to redirect user between form sets. You can find more information and examples in our documentation here.
1 Like
Thanks again for the solution @mnikitina, but I have another problem, when I use the formCommand.load function for redirecting from a display form panel, the original display form is still open underneath the edit form, how can I close the display panel form once the edit form is open?
thanking you in advance!
Hello @Jamal_Smith-Graham,
Please share the code you are using so I could reproduce this behavior.
Thank you!
Hiya @mnikitina
Here is the function that is run when a button is pressed:
//Function to update commentType field and redirect when button it is pressed:
window.commentButtonPressedRedirect = function (commentType){
var listId = fd.spFormCtx.ListAttributes.Id;
var itemId = fd.itemId;
var currentItems = pnp.sp.web.lists.getById(listId).items;
//Update item with the commentType
currentItems.getById(itemId).update({
CommentType: commentType,
}).then(function (result){
//Load the edit form
if (fd.isPanel) {
const formCommands = new window.Plumsail.FormCommands({
webUrl: fd._formManager._webUrl,
listId: listId,
listUrl: fd._formManager._listUrl,
culture: _spPageContextInfo.currentUICultureName,
language: _spPageContextInfo.currentLanguage,
componentLoader: window._spComponentLoader
});
formCommands.load().then(function() {
formCommands._openPanel({
itemId: itemId,
contentTypeId: fd.contentTypeId,
formType: "Edit",
rootFolder: fd.rootFolder
});
});
} else {
//replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
window.location.href = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/listform.aspx?PageType=6&ListId=" + listId + "&ID=" + itemId;
}
});
}
@Jamal_Smith-Graham,
Ok, I see two panels are open. Thank you!
You can add fd.close() to the code to close the original panel and open a new one, like this:
//Function to update commentType field and redirect when button it is pressed:
window.commentButtonPressedRedirect = function (commentType){
var listId = fd.spFormCtx.ListAttributes.Id;
var itemId = fd.itemId;
var currentItems = pnp.sp.web.lists.getById(listId).items;
//close original panel
fd.close();
//Update item with the commentType
currentItems.getById(itemId).update({
CommentType: commentType,
}).then(function (result){
//Load the edit form
if (fd.isPanel) {
const formCommands = new window.Plumsail.FormCommands({
webUrl: fd._formManager._webUrl,
listId: listId,
listUrl: fd._formManager._listUrl,
culture: _spPageContextInfo.currentUICultureName,
language: _spPageContextInfo.currentLanguage,
componentLoader: window._spComponentLoader
});
formCommands.load().then(function() {
formCommands._openPanel({
itemId: itemId,
contentTypeId: fd.contentTypeId,
formType: "Edit",
rootFolder: fd.rootFolder
});
});
} else {
//replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
window.location.href = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/listform.aspx?PageType=6&ListId=" + listId + "&ID=" + itemId;
}
});
}
1 Like
Thanks @mnikitina!
I ended up changing your code a little bit as I don't want the form to close if it isn't a panel! This was my final code! Thanks again
//Function to update commentType when it is pressed:
window.commentButtonPressedRedirect = function (commentType){
var listId = fd.spFormCtx.ListAttributes.Id;
var itemId = fd.itemId;
var currentItems = pnp.sp.web.lists.getById(listId).items;
//Update item with the commentType
currentItems.getById(itemId).update({
CommentType: commentType,
}).then(function (result){
//Load the edit form
if (fd.isPanel) {
const formCommands = new window.Plumsail.FormCommands({
webUrl: fd._formManager._webUrl,
listId: listId,
listUrl: fd._formManager._listUrl,
culture: _spPageContextInfo.currentUICultureName,
language: _spPageContextInfo.currentLanguage,
componentLoader: window._spComponentLoader
});
formCommands.load().then(function() {
formCommands._openPanel({
itemId: itemId,
contentTypeId: fd.contentTypeId,
formType: "Edit",
rootFolder: fd.rootFolder
});
//close original panel
fd.close();
});
} else {
//replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
window.location.href = "https://1651.sharepoint.com/sites/Core4/_layouts/15/listform.aspx?PageType=6&ListId=" + listId + "&ID=" + itemId;
}
});
}
1 Like