Support Forum

Ask questions and get help from MobileTogether experts.
MobileTogether Product Information
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
Yannic  
#1 Posted : Thursday, April 11, 2019 9:58:44 AM(UTC)
Yannic

Rank: Member

Groups: Registered
Joined: 11/21/2018(UTC)
Posts: 27

Thanks: 6 times
I was wondering if there is a way to get any information about the user thats currently using my app/workflow so i could work with this in my application without asking him anything?
bbv  
#2 Posted : Thursday, April 11, 2019 12:17:01 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 498

Was thanked: 88 time(s) in 88 post(s)
If you are using the user management of MobileTogether Server, then you can retrieve user name and user roles via variables:

$MT_UserName
$MT_UserRoles
thanks 1 user thanked bbv for this useful post.
Yannic on 4/16/2019(UTC)
Yannic  
#3 Posted : Thursday, August 15, 2019 3:23:15 PM(UTC)
Yannic

Rank: Member

Groups: Registered
Joined: 11/21/2018(UTC)
Posts: 27

Thanks: 6 times
Hello,

i have the problem that "$MT_UserName" is working without an issue, however "$MT_UserRoles" is empty even though several roles a given to the user. Do I miss something?
bbv  
#4 Posted : Friday, August 16, 2019 9:36:49 AM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 498

Was thanked: 88 time(s) in 88 post(s)
We will need your MT Server database and the app to see why it is empty. Please contact Altova Support if you don't want to expose them here
Yannic  
#5 Posted : Monday, August 19, 2019 8:56:13 AM(UTC)
Yannic

Rank: Member

Groups: Registered
Joined: 11/21/2018(UTC)
Posts: 27

Thanks: 6 times
I already found the issue, but i dont know a solution for it:
"$MT_UserRoles" only works if my project has the "server access" property set to "always". However, I want to use the application mainly offline. Is there a way to load this kind of information when a button is clicked or something like that?
bbv  
#6 Posted : Monday, August 19, 2019 10:48:25 AM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 498

Was thanked: 88 time(s) in 88 post(s)
What about saving its status on very first access in a persistent tree?
thanks 1 user thanked bbv for this useful post.
Yannic on 8/19/2019(UTC)
Yannic  
#7 Posted : Tuesday, August 20, 2019 11:05:24 AM(UTC)
Yannic

Rank: Member

Groups: Registered
Joined: 11/21/2018(UTC)
Posts: 27

Thanks: 6 times
What do you think would be the best way to get multiple (not all) User roles into a xml-file?
The idea is to define some roles with the same beginning word and put them all into a list from where to user has to choose which one he will use.
My problem is that atm i can only save all roles in one attribute, but not one by one in elements.

Edit: Is there any way to force a connection to the server, so i could actually loop over "MT_UserRoles"?
bbv  
#8 Posted : Tuesday, August 20, 2019 6:35:37 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 498

Was thanked: 88 time(s) in 88 post(s)
You can do it like that:

Code:
Append to Node
	$PERSISTENT/Root
  
new Node(s)
	for $r in $MT_UserRoles
	where starts-with( $r, 'Role' )
	return element UserRole { $r }


with this loop you are going through user roles and adding for those starting with the name 'Role' elements to the PERSISTENT tree. You will get as many such child UserRole elements under the Root as there are such roles.

To enforce doing something on server, simply use command
Code:
Execute On Server


So you could put the Append to Node command from above into Execute On Server - that's it
Yannic  
#9 Posted : Wednesday, August 21, 2019 1:16:23 PM(UTC)
Yannic

Rank: Member

Groups: Registered
Joined: 11/21/2018(UTC)
Posts: 27

Thanks: 6 times
When I use your code on an empty solution, just with an button and a label field, I doesnt work.
So I didnt copied the "where..." line of course, but the rest is all the same.

The solution is in the attached files, so you can have a look if I did something wrong.
File Attachment(s):
Test.mtd (5kb) downloaded 32 time(s).
bbv  
#10 Posted : Friday, August 23, 2019 1:39:21 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 498

Was thanked: 88 time(s) in 88 post(s)
Because you added an attribute UserRole under $PERSISTENT/Root. But my code adds elements UserRole. Because an XML node can have only one attribute with the same name and deliberate amount of elements
Yannic  
#11 Posted : Monday, August 26, 2019 12:28:19 PM(UTC)
Yannic

Rank: Member

Groups: Registered
Joined: 11/21/2018(UTC)
Posts: 27

Thanks: 6 times
Yes, I see my mistake. Thank you.
Now it works fine for me.

However, i want motify your statement above, so the Roles that would get saved have the attributes 'key' and 'value', each one filled with one part of the role.

Code:

for $r in $MT_UserRoles
	where starts-with($r, 'Role')
    return element UserRole {
		attribute Key { substring(string(.), 9, 13) },
		attribute Value { substring(string(.), 13) } 
    }


This doesnt get me any UserRole-elements back.
bbv  
#12 Posted : Monday, August 26, 2019 8:03:23 PM(UTC)
bbv

Rank: Administration

Groups: Registered, Administrators
Joined: 7/21/2014(UTC)
Posts: 498

Was thanked: 88 time(s) in 88 post(s)
$r contains the name of the role. Therefore a correct statement would be:

Code:
for $r in $MT_UserRoles
    where starts-with($r, 'Role')
    return element UserRole {
        attribute Key { substring($r, 9, 13) },
        attribute Value { substring($r, 13) } 
    }
Users browsing this topic
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.