- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Check if a folder exists in a JMP Live space
Hello,
Using JSL in JMP18 I can create new folders in both my personal space and in other spaces on JMP Live using the 'Create Folder' function. When I create folders in my personal space, I can use the JSL 'Find Folders' function to list all existing folders first and check if my new folder already exists. I could then assure unique folder names trough JSL.
The default behavior of JMP Live is to create unique folder names by adding " (n)" to the folder name with 'n' being the count of the number of folders with the same name. But I would like to avoid this.
In other JMP Live spaces, not my personal space, I observe the same behavior: identical folder names are automatically appended by " (n)". However, the 'Find Folders' function does not have the Space Key as a parameter so I cannot check for already existing folders on spaces that are not my personal space.
I find that the only function that accepts the space key as a parameter is the 'Create Folder' function. I checked the relevant JSL help page here, but this situation is not described.
What is the recommended approach to extract existing folders on a JMP Live space? or am I missing the obvious here?
Thanks!
Paul
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Check if a folder exists in a JMP Live space
Did you try dropping this part from the Find Folders
Publisher( user )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Check if a folder exists in a JMP Live space
I'm not familiar with JMP Live, but have you tried increasing the page size for the query (or utilized Next() call)? Scripting Index can have some examples which you cannot find from JMP Help page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Check if a folder exists in a JMP Live space
Thanks Jarmo,
No, I did not try this yet. here is my code that works well for checking for existing folders in a personal space.
There is no code included that assures a unique folder name (for simplicity's sake) but that could easily be created.
As I stated in my post: it appears that Find Folders function does not have a space key and by default runs the query in my personal JMP Live space.
I am guessing that the PageSize parameter in FindFolders can be used to page through a long list of folders (should they exist).
// open the connection to JMP Live
liveConnection = New JMP Live( Connection( ) );
// get the user name from JMP Live
user = liveConnection << Get Username;
// get the existing folders already in my Space
getFolders = liveConnection << Find Folders( Publisher( user ) );
folderlist = getFolders << As Scriptable();
// Define the folder name you want to check or create
folderName = "new_folder_name";
// Define the space key of the Space you wish to create the folder in
spaceKey = "~"; // set key to "~" for your personal space or use the space key
// Initialize a variable to store the folder ID
folderID = .;
// Check if the folder exists. If it exists, folderID will contain the ID
// if the folder does not exist, folderID will contain a missing value
For( i = 1, i <= folderlist << Get Number Of Items, i += 1,
If( folderlist[i] << Get Title == folderName,
folderID = folderlist[i] << Get ID;
Show( folderID );
Break();
)
);
// If the folder does not exist, create it. folderID will contain the folder ID.
If( Is Missing( folderID ),
newFolder = liveConnection << Create Folder(
Space( spaceKey ), // Use "~" for personal space or specify the space key
Title( folderName ),
Description( "Automatically created folder." )
);
folderID = newFolder << As Scriptable;
folderID = folderID << Get ID;
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Check if a folder exists in a JMP Live space
One more comment, if I run the Find Folders function and I manually inspect the returned list, I can see that there is a list entry for each folder in my personal space. There are no other entries (while I have access to other spaces with folders).
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Check if a folder exists in a JMP Live space
Did you try dropping this part from the Find Folders
Publisher( user )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Check if a folder exists in a JMP Live space
Hi Jarmo,
Thanks for the suggestion. It turns out to be the winner!
This code (adding the Search function as a parameter to the Find Folders function):
// open the connection to JMP Live
liveConnection = OpenJMPLiveConnection( );
foldername = "foldername";
// get the existing folders already in my Space
getFolders = liveConnection << Find Folders( Search( foldername ) );
folderlist = getFolders << As Scriptable();
Show(folderlist);
returns the name, description, ID and URL of the folder if it exists outside my personal space.
Paul