Dynamicaly change the Data Source Site URL of a Library

As described in this Documentation Site, I can dynamically change the Root Folder of a LIst or Libary.
Show docs from one folder only in List or Library control — SharePoint forms (plumsail.com)

For my intended solution, it is essential to set the Site URL dynamically. Sadly, I could not find any documentation or community post. Do you know how to change the site URL with JS?

Thanks!

Hello @andy,

You can change the List or Library control source site, list and the view with the code:

//set the source site
fd.control('Control1').webUrl = '/sites/MainSite/SubSite';

//set the source list or library
fd.control('Control1').listUrl = 'Lists/List1';

//set the list view by name
fd.control('Control1').viewName = 'All Items';

//set the list view by ID
fd.control('Control1').viewId = 'FEB4302C-617F-4B6B-86F2-9A3F718E4F58';
1 Like

Hi @mnikitina

I beleave you had a typo in your previous post, in the set list or library line .WebUrl ist defined again, i believe it should be:
fd.control('Control1').listUrl = 'Lists/List1';

Anyway I tried to execute the code inside fd.spRendered(function() {} or also inside a button without success (the list remains as initially set):

var dt = fd.control('ListOrLibrary3');
dt.ready(function() {
setRootFolder();
});

function setRootFolder(){
    
console.log(fd.control('ListOrLibrary3'));    
//set the source site
fd.control('ListOrLibrary3').webUrl = '/sites/MainSite/rw-test2';

//set the source list or library
fd.control('ListOrLibrary3').listUrl = 'Lists/test';

//set the list view by name
fd.control('ListOrLibrary3').viewName = 'viewtest'

console.log(fd.control('ListOrLibrary3'));    
}

I also tryed to reload the list fd.control('ListOrLibrary3').refresh(); whiteut success.

do you have any idea? i don't get any errors in the console either.

Thanks and reagards!

@andy,

You have a sharp eye! I've updated the code in my post.

The code should work, please try changing only one thing at once, for instance, source list:

fd.spRendered(function() {
    var dt = fd.control('ListOrLibrary3');
    dt.ready(function() {
        //set the source list or library
        fd.control('ListOrLibrary3').listUrl = 'Lists/test';
    });
});

If that still doesn't work, please check the browser console for errors. Also make sure that you have the latest version of the desktop designer (3.3.2) and the app package (1.1.0).

I use desktop designer (3.3.2) and the app package (1.1.0). I also tried to run the code on a different tenant, empty list etc.. The form also stays the same if I only try to change the library within the same SP Site collection.

Strangely, I don't get any errors in the console; also, no changes are to be found when logging the list. When I use the control to change the frontend (like hiding buttons), it works...

fd.spRendered(function() {
console.log(fd.control('ListOrLibrary2'))
var dt = fd.control('ListOrLibrary2');
dt.ready(function() {
//fd.control('ListOrLibrary3').webUrl = '/sites/MainSite/rw-test2';
//set the source list or library
fd.control('ListOrLibrary1').listUrl = 'Lists/test';
});
console.log(fd.control('ListOrLibrary2'))
fd.control('ListOrLibrary2').ready().then(function(dt) {
//set the source list or library
fd.control('ListOrLibrary2').listUrl = 'Lists/test';
//hide Delete on load
dt.buttons[1].visible = false;
dt.buttons[0].visible = false;
});
});

I hope we can make this possible, as it would help me substantially.

@andy,

Not sure why it doesn't work for you.

Please define fd globally, comment out all other custom code and save the form:

window.fd= fd;

image

Then, open the form in browser and try changing the list URL or the view from the browser console:
image

If possible, please record a short video for me.


(the doclyb shown in the video is the standard SP doclyb and not the newly created test doclyb)
I hope this helps.

@andy,

Thank you for the video!

The document library server-relative URL doesn't include Lists folder. Please specify only the name of the document library like so:

fd.control('ListOrLibrary1').listUrl = 'Shared Documents'

Regarding this error:
image

It indicates that the control's name is invalid. Please double check the control's internal name and try again.

@mnikitina
The screenshot you made was the second try. I tested if I would get an error by typing a nonexistent list.

You see that it worked on the first try (with the correct list). But did not change the connection to the list.

image

The error on your screenshot indicates that the control with that name doesn't exist.

These are errors when specifying a path to a non-existent list or library:

What is the source of the List or Library control? Is it a list or library? The new path you enter: Liste/test; what type is it: list or library?