Hello Community,
I am using two 'Lists or Library' control in my single form.
I have two different list views for a form that i want to use 'List or Library' control, so I use these two views for two 'List or Library' control.
My problem is when I try to create a new item it will show form for view1 for both views.
So, is there any way that i can achieve this,
or any other way I can redirect form according to the list view?
Hello @Margo,
Yes i want to set up custom routing
Let's say I have one Child list name 'Employee', that contains some columns for personal information like 'FirstName', 'LastName' etc, and some columns that help to store data for organization use like 'Salary', 'Hours', 'Position' etc.
So i have to use two list or library control one for personal information and other for organization data.
So I create two list view View1 (for Firstname, lastname) and View2 (salary, hours).
in child list i want two different form respectively to these two list or library control.
i am looking for routing child list form according to view, so i can redirect the user to form for 'Personal Information' and 'Data for Organization'.
You can use the code below to open the corresponding form set from List or Library control.
Please add this code to JavaScript Editor >> Current Form section in the parent form:
function selectFormSet(dt, formSetId) {
var funcName = dt._listViewManager.openDialogFuncName;
var func = window[funcName];
window[funcName] = function(url, pageType) {
window.FormSet = formSetId;
func(url, pageType);
}
}
fd.spRendered(function() {
fd.control('SPDataTable1').ready().then(function(dt) {
//replace with the Forms Set ID for view 1
selectFormSet(dt, 'df788428-cab9-41f4-8583-4ab8b41e0a28');
});
fd.control('SPDataTable2').ready().then(function(dt) {
//replace with the Forms Set ID for view 2
selectFormSet(dt, '27f0b45a-f904-42d4-b28e-f37d581e36f6');
});
});
Please add this code to the JavaScript Editor >> Custom Routing section in the child form:
I want achieve something like rout list or library according to currant users language.
i have list or library same as above, in child form i created two different form set for different language.
so in parent form while English user try to open form, in child he could see english form and other language person can see their relative form.
Hello @Margo,
I was use routing based on current users language in parent form already, but I want that list or library control also should open forms for different languages.
How can I do that?
Thanks for the sample code provided in the July 20 post. The formset routing works great when the list/library control is opened from the parent form that happens to be the 'top' form. If the parent form is opened in a dialog from another form (top most form), I cannot get the list/library control to route to the correct formset anymore on new item click of the list/library control. How can we get routing to the correct formset to work when the parent form is not the 'top' most form but is opened in a dialog from another Plumsail form page that is the originating or 'top' most form?
You can save the form set ID in the localStorage and get it in routing.
Add this code to the JavaScript editor:
function selectFormSet(dt, formSetId) {
var funcName = dt._listViewManager.openDialogFuncName;
var func = window[funcName];
window[funcName] = function(url, pageType) {
localStorage.FormSet = formSetId;
func(url, pageType);
}
}
fd.spRendered(function() {
fd.control('SPDataTable1').ready().then(function(dt) {
//replace with the Forms Set ID for view 1
selectFormSet(dt, 'c46596f4-3325-43d5-86f9-77fc72d52ad4');
});
});
I am trying to open a formset in dialog on fileupload but it only opens my default edit page.
I do not have any errors but i cannot seem to figure it out. Could you please help?
My code as follows:
fd.spRendered(function(){
OpenMetadata();
});
function selectFormSet(dt, formSetId) {
let siteRelativeUrl = _spPageContextInfo.webServerRelativeUrl;
let listId = fd.spFormCtx.ListAttributes.Id;
let formId= 'b72cef8a-f671-45e2-ba9d-d288c6ab6881';
//let dialogUrl = siteRelativeUrl + "/_layouts/15/listform.aspx?PageType=6&ListId=" + listId + "&ID=" + fd.itemId;
let dialogUrl = siteRelativeUrl + "/Pages/EditForm.aspx?ItemID=" + fd.itemId;
var funcName = dt._listViewManager.openDialogFuncName;
var func = window[funcName];
console.log(funcName, func, dt)
window[funcName] = function(url, pageType) {
window.FormSet = formSetId;
func(url, pageType);
}
func(dialogUrl, 6)
}
function OpenMetadata(){
fd.control('InitialFilesTable').ready().then(function(dt) {
fd.control('InitialFilesTable').$on('filesUploaded', function(itemIds) {
selectFormSet(dt, 'b72cef8a-f671-45e2-ba9d-d288c6ab6881');
});
});
}
I tried setting the url in both ways (commented and uncommented 'dialogUrl').
Please make sure you've added the code to the custom routing tab and test the code I've originally shared:
function selectFormSet(dt, formSetId) {
var funcName = dt._listViewManager.openDialogFuncName;
var func = window[funcName];
window[funcName] = function(url, pageType) {
localStorage.FormSet = formSetId;
func(url, pageType);
}
}
fd.spRendered(function() {
fd.control('SPDataTable1').ready().then(function(dt) {
//replace with the Forms Set ID for view 1
selectFormSet(dt, 'c46596f4-3325-43d5-86f9-77fc72d52ad4');
});
});
Hello @Margo,
I have added the following the custom routing:
I still get the default form and not the formset I need. Maybe it's the URL that I have not correctly configured when I call the function func(url,pageType)? Is this url configuration correct? siteRelativeUrl + "/_layouts/15/listform.aspx?PageType=6&ListId=" + listId + "&ID=" + fd.itemId
@Margo
When I use it without URL, there is no dialog-box to be seen. I do not see any errors either.
Use case so that we are on the same page:
I have a form that has multiple formsets:
When I upload a file on the list or library control on Default formset, I want to show a dialog with the 'AdhocReview Popup' (rf. pic above) formset.
The above code doesn't not seem to work for me - Either I get no popup (when i do not build a URL) or it just opens the same default form in the popup too.
Thank you for the details! You can use Dialog.open() method to open the form in a dialog like so:
function openDialog(formSetId) {
//save Form set ID to local storage
localStorage.FormSet = formSetId;
Dialog.open("Form_URL")
}
fd.control('SPDataTable1').ready().then(function(dt) {
fd.control('SPDataTable1').$on('filesUploaded', function(itemIds) {
openDialog('9c49268c-8d61-4069-99b3-ff394cbb07dd');
});
});
And use this code for custom routing:
if(localStorage.FormSet){
//get form set ID
var FormID = localStorage.FormSet;
//clear form set ID
localStorage.FormSet = ''
return FormID;
}
Note that your approach might cause the save conflict