Trouble creating user-specific links within a jmp tableProblem: I have a jmp file that lives in a shared OneDrive folder. Other colleagues sync this OneDrive folder to their desktop so that we all have easy access to the shared jmp file. Inside the jmp file are links to other files that live in the same shared folder as the jmp file. Because each person has a user-specific OneDrive file path, my links are actually formulas which detect the user-specific file path to then set the user-specific appropriate link. Unfortunately, these formulas aren't automatically rerun when someone new opens the jmp file. I've explored two options to resolve this and am not a fan of either:
1. have a 'rerun formulas' script that you must run before using a link: unfortunately, people forget about this script. Furthermore, people commonly make subsets of the data and then try to run the 'rerun formulas' script but it doesn't work because formula evaluations are suppressed by default.
2. save a 'rerun formulas' script as 'OnOpen' so it runs as soon as someone opens the jmp table: unfortunately, this results in a prompt appearing (attached) and people are too scared to say 'yes' when it opens because they are afraid it'll ruin something (they don't even know what it's for)
Questions
1. Is there a way to make a hyperlink update as soon as it's clicked?
2. Can I suppress the 'OnOpen' pop-up or edit the pop-up to explain what the user should do?
3. Is there another way besides an 'OnOpen' script that would enable formulas to update as soon as a jmp table is opened?
Any help is appreciated. Thanks!
Matt
Re: Trouble creating user-specific links within a jmp tableHi @Matt_Converse. Good question. I'm thinking that your best option would be to generalized the paths in the shared file such that they are built at runtime. Not knowing the details of this file, it would be impossible to give specifics, but may very well involve expression handling. As for your other three options:
- Hyperlinks are typically hard-coded. I'd have to know more about how and where you're using them.
- Yes. Problem is, you'd need to alter the users User Preferences before OnOpen was run.
- Not that I'm aware of
Re: Trouble creating user-specific links within a jmp tableHey @DonMcCormack!
Thanks for the prompt reply. I'm happy to add more detail. Here's an example of how the links (i.e., paths to files/folders) vary:
- my file path to a folder of SEM images: C:\Users\mconvers\OneDrive - W. L. Gore & Associates, Inc\Example Shared Database\SEM Library\4391
- my colleagues file path to the same folder: C:\Users\mjohnson\OneDrive - W. L. Gore & Associates, Inc\Example Shared Database\SEM Library\4391
In the example table ("Table1.jmp", attached), you'll see how I use a formula in the "SEM Folder Path" column to determine a user-specific folder path. It essentially reads the file path of the main table ("Table1.jmp") to get the user-specific directory and then appends "SEM Library..."
dt_name = "Table1";
dt = Data Table( dt_name );
path_full = dt << Get Path();
name_file = dt_name || ".jmp";
n = Munger( path_full, 1, name_file );
path_folder = Substr( path_full, 1, n - 1 );
path = path_folder || "SEM Library" || "\" || Char( :Database Number );
I then use an event handler to set the hyperlink ("SEM Folder Link" column). I've attached a full zipped folder in case it helps you get a sense of the overall file structure, too.
I'd love to hear more about how I might "generalize the paths in the shared file such that they are built at runtime". Thanks!
Matt
Re: Trouble creating user-specific links within a jmp tableYou can use the %OneDrive% windows system variable to get the users path to the base one drive folder;
use Get Environment Variable( "ONEDRIVE" ); to call it and use in the url.
Re: Trouble creating user-specific links within a jmp tableHow about something like the attached? I've shortened the folder path to contain the part common to all users and changed the event handler to build the remaining portion (i.e., the unique part) of the path.
Re: Trouble creating user-specific links within a jmp tableYou can also use the Get Environment Variable( "ONEDRIVE" ); in the event handler... as you don't want it running for every row, just when it is needed 
Also it probably doesn't work for Macs and Linux machines unless the OneDrive system variable is setup...
If the JMP file is going be only in one place on the network (say in the "Example Shared Database" folder ) you could also use a url formatted as a relative path.
i.e. path = "..\SEM Library\" || Char( :Database Number );
This should even work on Macs....but the jmp file has to be in the folder directly up from "SEM Library"
Re: Trouble creating user-specific links within a jmp tabledoh... relative path would be a single dot for the current folder....
path = ".\SEM Library\" || Char( :Database Number );
Re: Trouble creating user-specific links within a jmp table@DonMcCormack, that worked great! (I just had to change one forward slash to a backslash)
I think your edited script addresses the first part of my issue, that is, the links get built at runtime. However, the second challenge my users commonly run into is that they make subsets of this table and then hope to follow links. Unfortunately, the subsets aren't saved and therefore don't have a file path to read. Any suggestions here?
I could use @DByss's suggestion to get the user's onedrive-specific environment, but there is a file path structure between that and "Table1" that I have seen some users change (so even that may not be consistent from user to user).
Thanks for all the help!
Matt
Re: Trouble creating user-specific links within a jmp tableHere's an idea. Save the columns needed to access the directories lists. Add an ID column (sequentially numbered from 1 to N Rows) as the first column. Replace the event handler script with this
Function( {thisTable, thisColumn, iRow},{rowID},
If(!Namespace Exists("myCustomFunctionNamespace"),
New Namespace("myCustomFunctionNamespace");
myCustomFunctionNamespace:thisPath = Substr(thisTable << Get Path,1,Contains(thisTable << Get Path,"/",-1));
myCustomFunctionNamespace:semFolderPath = Column(thisTable,"SEM Folder Path << Get Values");
);
rowID = Column(thisTable,1);
Open(Char(myCustomFunctionNamespace:thisPath || "/" || myCustomFunctionNamespace:semFolderPath[ rowID] ));
);
The column values get loaded into lists and all the operations are based on these values rather than something that needs to be looked up in a table (except the ID value, which references the row number from the original table).
Re: Trouble creating user-specific links within a jmp tableThanks, @DonMcCormack! I added an ID column and replaced the event handler; however, I get this error when clicking on the link in row 1: "Subscript problem at row 1 in access or evaluation of 'myCustomFunctionNamespace:semFolderPath[ /*###*/rowID]'". Do you get what the "/*###*/" is referring to? I know we're close because I can get the script to run outside of a function (see my saved script). Note that I'm just testing the link before making a subset (haven't tried it with a subset yet).
Really appreciate your help.
Matt
Re: Trouble creating user-specific links within a jmp tableSorry about that @Matt_Converse. The second to last line of code should be
rowID = Column(thisTable,1)[iRow]
You want to reference the value from the first column in the selected row (from the subset). The way I had it, it was referencing the entire column.
Re: Trouble creating user-specific links within a jmp table@DonMcCormack, I should have caught that! Thank you! This works for subsets now, too! I'm going to have to start using event handlers more often! Really appreciate the help.