Using the LabKey JavaScript client API, I'm trying to save/update a view via Query.getQueryViews() and Query.saveQueryViews(). When the latter call is creating a new view, it seems to create the view as a private view. Subsequent calls to saveQueryViews() update the view. Fine.
However, if the user then manually changes that view to be a public view, the next time my code tries to update the view, I get an error - I'm pretty sure because it's actually trying to create a new, private view whose name is already taken by the public view, rather than trying to update the existing view.
I see a similar problem using the built-in LabKey "Customize View" (not using my code at all): If I create a view, and save it as public, then try to re-save it as private, I get an error.
I don't see anything in the API of getQueryViews() or saveQueryViews() to indicate whether the view is public or private. Given that the default (only?) behavior of saveQueryViews() is to create/update a private view, it seems that I can never update a public view via saveQueryViews().
Am I missing something? Thanks for any light anyone can shed on this.
Andy Straw
University of Rochester
Andy |
|
Andy Straw responded: |
2014-01-06 13:42 |
As I have experimented with this more, what I'm seeing is that there end up being two views with the same name: one public, and one private. If you go to Manage Views, you see only the public one; if you delete that one, the private one then shows up. Similarly, only one shows up in the View menu, and it seems to be the public one; if you delete it, then the private one shows up.
When my code tries to update the view, it always updates the private one.
- If there is only a private one, that one gets updated, and everything works fine.
- If there is only a public one, it seems to be able to create a private one with the same name. But now there are two views where I really only want one, and on subsequent attempts to update the view...
- If there are both a public and a private, I get an error.
If I could get public/private info about the view from getQueryViews() and set public/private on the view in setQueryViews() I could always update the single view.
Andy |
|
Andy Straw responded: |
2014-01-06 14:00 |
Note the behavior I'm seeing with my code also occurs just using "Customize View": create a view as public to start with, then save another with the same name as private - you _CAN_ save the two views with the same name. But if you try to save again as private (you're really trying to save the public view as private), you get an error.
Andy |
|
jeckels responded: |
2014-01-06 17:46 |
Hi Andy,
You should be able to use the "shared" property (a boolean) in the response from getQueryViews() to see if an existing view is public or not.
Similarly, as it sounds like you've discovered, you can control whether a saved view is public or not with the "shared" property when saving. However, looking at the code, it looks like it may handle promoting a private view to be public, but not the other way around.
As a client-side workaround, one possibility would be to call deleteView API. It's not exposed via a JavaScript wrapper in LABKEY.Query, but an example usage from the Customize View UI looks like:
Ext.Ajax.request({
url: LABKEY.ActionURL.buildURL("query", "deleteView", this.containerPath),
jsonData: {schemaName: this.schemaName, queryName: this.queryName, viewName: this.viewName, complete: complete},
method: "POST",
scope: this,
success: function() { window.location.reload() }
});
Can you reply with the error you're getting when saving when both public and private versions already exist?
Thanks,
Josh |
|
|
|