Skip navigation.
spilling the beans

publish views

users
| | |

Publishing users' view is still far from a quick and simple process in TM1.
First, the admin cannot see other users' views.
Second, users cannot publish their own views themselves.
So publishing views always require a direct intervention from the admin, well not anymore :)

1. create a process with the following code
in Advanced->Parameters Tab
Parameters Cube, View, Overwrite (all String type)
parameters publish view
in the Advanced->Prolog Tab
prolog publish view

if((ViewExists(Cube,View) =0) % ((ViewExists(Cube,View) =1) & (Overwrite @= 'Y')));

#get UserName
If(SubsetExists('}Clients','WhoAmI') = 0);
SubsetDestroy('}Clients','WhoAmI');
Endif;
StringMDX = '{TM1FILTERBYPATTERN( {TM1SUBSETALL( [}Clients] )}, USERNAME )}';
SubsetCreatebyMDX('WhoAmI',StringMDX);
User=SubsetGetElementName('}Clients','WhoAmI',1);
SubsetDestroy('}Clients','WhoAmI');

#copy view to public space
TM1Path='E:\TM1Data\TM1Server\';
Query = 'cmd /c mkdir '| TM1Path|Cube |'}vues';
ExecuteCommand(Query,0);
Query = 'cmd /c copy "'| TM1Path|User| '\'| Cube |'}vues\'| View |'.vue" "'| TM1Path|Cube |'}vues\'| View |'.vue"';
ExecuteCommand(Query,0);

#unload cube first to reload vues
CubeUnload(Cube);

Else;
ItemReject(View|' view in '|Cube| ' Cube already exists');
Endif;

2. change the TM1Path and save
3. in Server Explorer, Process->Security Assignment, set that process as Read for all groups that should be allowed to publish
Now your users can publish their views on their own by executing this process, they just need to enter the name of the cube and the view to publish.



The code in the above Prolog Tab can be replaced with these 5 lines:

if((ViewExists(Cube,View) =0) % ((ViewExists(Cube,View) =1) & (Overwrite @= 'Y')));
PublishView(Cube,View,1,1);
Else;
ItemReject(View|' view in '|Cube| ' Cube already exists');
Endif;

That's it :) Thanks to the anonymous reader (please register if you want to be credited) for the suggestion.


Average rating
(2 votes)

Check to see whether the view exists

Would be a good idea to check whether the view exists and skip the shell copy process if it does. Or add an extra parameter to confirm overwrite existing view.

I also realized that if the Cube does not have a \}vue\ folder, the process returns a successful execution but no file is copied.


input validation checks

great suggestions.
unfortunately the ViewExists function is unable to verify private views. Although the user is executing the process and the returned username is the correct user, the access rights belong to Admin so it cannot see the users'view.
I should also check for code injection against input from malicious users that could get executed in the shell.

For now, I added a flag to confirm overwriting a public view with a private one.


Nice one!

Thanks for this