Set attribute based on when the user logges in?

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
lueu
Posts: 89
Joined: Tue Mar 07, 2023 11:49 pm

Set attribute based on when the user logges in?

Post by lueu »

I am wondering if it is possible to set an attribute with a rule and/or a process that will run when the user logges in? Or maybe when the query is run?
My query is an EXEC_SP, and I use input control in the panel operation where the user can select year. But I would like the initial value to be current year without having to manually update the initial value feild every year.

I would think I could set the attribute to current year with someting like this: LoggedInRegularUser.BudsjettAar=YEAR(CURRENT_TIMESTAMP), but how do I get it to "Kick in"?
Jaymer
Posts: 2454
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Set attribute based on when the user logges in?

Post by Jaymer »

All users log into a VP, even if its the default one.

Run a process. Do some checking and setting of defaults in that process.
You can add other flags to the RegUser table - isManager, AccountingYN, SalesTeam, etc.

Then in the Login process, check those flags to do extra things for just those user types.

Sure, you can mess with Access Levels, or multiple Roles, but sometimes a simple Toggle indicator assigned to a user is enough.
Attachments
lueu1.png
lueu1.png (38.33 KiB) Viewed 76386 times
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
UnionSystems
Posts: 197
Joined: Fri Jun 17, 2016 7:10 am
Location: Brisbane Australia
Contact:

Re: Set attribute based on when the user logges in?

Post by UnionSystems »

Another option available in AwareIM to record login activity is Login Notification described at https://www.awareim.com/dokuwiki/doku.p ... gin_events

This also enables you to record login failures as well as when a user logs out.
AWS Linux, Windows Server, AIM 8.4 & 8.6
lueu
Posts: 89
Joined: Tue Mar 07, 2023 11:49 pm

Re: Set attribute based on when the user logges in?

Post by lueu »

Notice that I forgot to answer this one! Thanks for all answers, I managed to set up the LoginNotification based on your help :D

Now I have another question about this notification. I notice that there is no UserID attribute, and I think I need one to compare the user ID for logged in user against RegularUserID (somthing like LoggedInRegularUser.ID= RegularUser.ID) to fetch the correct data in my query on a view.

Anyone done this and have any tips on how to achieve this? Could I just add the attribute? Can't seem to find any good examples in the documentation or on the forum for what I want to achieve.
UnionSystems
Posts: 197
Joined: Fri Jun 17, 2016 7:10 am
Location: Brisbane Australia
Contact:

Re: Set attribute based on when the user logges in?

Post by UnionSystems »

I do it by having a "When LoginNotification is received" rule with the following :

Code: Select all

IF LoginNotification.LoginName<>'BAS_Guest@@'  AND EXISTS RegularUser WHERE (RegularUser.LoginName=LoginNotification.LoginName )  THEN
	FIND RegularUser WHERE (RegularUser.LoginName=LoginNotification.LoginName ) TAKE BEST 1
 	 CREATE Activity WITH Activity.Type='Sign In' ,Activity.Created=CURRENT_TIMESTAMP,Activity.ps_RegularUser=ThisRegularUser,Activity.Summary=RegularUser.LoginName

2023-10-26 13_03_41-Aware IM Configuration Tool.png
2023-10-26 13_03_41-Aware IM Configuration Tool.png (29.07 KiB) Viewed 76250 times
In this case it is creating an "Activity" Object....you would need to change this to your own Object. Not also Activity.ps_RegularUser is a reference to RegularUser using the eagles9999 excellent attribute naming convention.
AWS Linux, Windows Server, AIM 8.4 & 8.6
lueu
Posts: 89
Joined: Tue Mar 07, 2023 11:49 pm

Re: Set attribute based on when the user logges in?

Post by lueu »

Thanks, Union!
Need to ask what 'BAS_Guest@@' is?

I am trying to see how I can alter this to fit my needs, but I'm not there yet. I can try to explain better what I am looking for, because I am not sure if what you are doing here can be transferred to what I am trying to do.

I had a stored procedure that worked fine, and this contained a WHERE @ID = RegularUser.ID. Doing an EXEC_SP in a qyery then gave med the correct data for the logged in user. Then I figured that you can't sort or filter when using stored procedure, so I made a view. In my view I can't use the @ID, and therefore I need to have a WHERE clause in my query on the view to replace the WHERE @ID = RegularUser.ID. I am studying the User guide about context, since I think everything I've tried so far haven't worked because I can't get the loginName from logged in user in context..

Appologice for the possibly bad explanaition..

Found this that makes me wonder even more why I get the "Possibly wrong object identifier"
"NOTE: The following instances of business objects are always accessible to rules
directly
– there is no need to find them using the FIND action, as they are always
implicitly present in any Context:
a. An instance of a business object representing logged in user (must be a member of
the SystemUsers group) – this instance can be referred to using LoggedIn prefix
(see Instance Prefixes), for example LoggedInLibraryMember where
LibraryMember is a business object belonging to the SystemUsers group"

Shouldn't this mean that I should be able to get to the LoggedInRegularUser.LoginName without any problems?
BobK
Posts: 545
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: Set attribute based on when the user logges in?

Post by BobK »

lueu wrote: Thu Oct 26, 2023 8:59 am Need to ask what 'BAS_Guest@@' is?
If you allow Guest entry by using http://localhost:8080/AwareIM/logonGuest.aw
'BAS_Guest@@' is the loginName of the guest.

lueu wrote: Thu Oct 26, 2023 8:59 am I am trying to see how I can alter this to fit my needs, but I'm not there yet. I can try to explain better what I am looking for, because I am not sure if what you are doing here can be transferred to what I am trying to do.
A piece of code from UnionSystems reply:

Code: Select all

FIND RegularUser WHERE (RegularUser.LoginName=LoginNotification.LoginName ) TAKE BEST 1
This will find the RegularUser object for the user logging in and from this you can get the RegularUser.ID

lueu wrote: Thu Oct 26, 2023 8:59 am Found this that makes me wonder even more why I get the "Possibly wrong object identifier"
"NOTE: The following instances of business objects are always accessible to rules
directly
– there is no need to find them using the FIND action, as they are always
implicitly present in any Context:
a. An instance of a business object representing logged in user (must be a member of
the SystemUsers group) – this instance can be referred to using LoggedIn prefix
(see Instance Prefixes), for example LoggedInLibraryMember where
LibraryMember is a business object belonging to the SystemUsers group"

Shouldn't this mean that I should be able to get to the LoggedInRegularUser.LoginName without any problems?
[edit]
I just looked at my code and I can access LoggedInRegularUser.LoginName. My code is in the Rules(received) tab for the Notification


Have you looked at using the "Initialization process" from the VP like Jaymer suggested in the first response to your original post. You should be able to use LoggedInRegularUser there.
Bob
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Set attribute based on when the user logges in?

Post by PointsWell »

The original question was:
I am wondering if it is possible to set an attribute with a rule and/or a process that will run when the user logges in? Or maybe when the query is run?
My query is an EXEC_SP, and I use input control in the panel operation where the user can select year. But I would like the initial value to be current year without having to manually update the initial value feild every year.

I would think I could set the attribute to current year with someting like this: LoggedInRegularUser.BudsjettAar=YEAR(CURRENT_TIMESTAMP), but how do I get it to "Kick in"?
Things have quickly become more complicated than is necessary.

Create a non persisted BO for Session Values (I would post an image of the screen but the forums board seems to be fubar at the moment).

Create an attribute that you want to store today's date in. Set the initial value to the current year. Then have your query point to this non persisted value.

The BO will be disposed of every time the user is logged out and recreated when they log in. The year will be set every time it is recreated.

When you put things into the LIRU the values are persisted which means they need to be refreshed. The non persisted sessions value is unique to each LIRU and is clean every time you log back in.

See
https://www.awareim.com/dokuwiki/doku.p ... ion_values
https://www.awareim.com/dokuwiki/doku.p ... ersistence
lueu
Posts: 89
Joined: Tue Mar 07, 2023 11:49 pm

Re: Set attribute based on when the user logges in?

Post by lueu »

PointsWell: I did the session object, but setting the initial value to the current year will not get me the correct data when 2024 starts, unless I go in there and manually changes initial value to 2024. How to solve this?
Also - yes, it might have become more complicated than necessary, but this is because I also need to get the users ID og LoginName for another match in addition to the current year. For me it felt natural to continue this post with that question since I feel this are connected, but I might be wrong.
Thanks for the help with the session object :)

BobK: Thansk for the answer, I will look into this :)
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Set attribute based on when the user logges in?

Post by PointsWell »

lueu wrote: Fri Nov 03, 2023 10:00 am PointsWell: I did the session object, but setting the initial value to the current year will not get me the correct data when 2024 starts, unless I go in there and manually changes initial value to 2024. How to solve this?
The Session Object is dropped when the user logs out and recreated when they log back in. The initial value will be generated every time. Hence when the user logs in on 31 Dec 2023 the year will be 2023, when they log in the next day it will be 2024. You can test this by using the current day if you are uncertain. Log in today and it will be 3, tomorrow it will be 4.
lueu
Posts: 89
Joined: Tue Mar 07, 2023 11:49 pm

Re: Set attribute based on when the user logges in?

Post by lueu »

Okey, so you mean I should set initial value by saying "CURRENT_YEAR" "GET_DATE" or something like that? Then I need to set it as a string and do some converting to compare with the years I have in my query. The query returns data for several years, and the user should be able to get only one year at the time, and the current year as default. I am using Input coltrol to let the user choose the desired year, and made it work by using session object in the user control, but as numbers. And then initial value also had to be a number. I'll try changing it to a string :)
lueu
Posts: 89
Joined: Tue Mar 07, 2023 11:49 pm

Re: Set attribute based on when the user logges in?

Post by lueu »

So I got my input control working with the session object, except for the part with the current year as initial value. I've tried different combinations for current year, year, timetstamp and so on, but nothing gives me the year as a value in my input control, and of course not any results. If I choose a year from my list of choices I will get the correct data. But I just don't get how to get the current year value in there! If anyone knows how to write that in initial value, I would be very greatful.

The session object SelecteYear is Plain text, since if I choose Date, I can't choose a format with only 'yyyy', and if I choose number, I can't write for example CURRENT_YEAR as Initial value.
BLOMASKY
Posts: 1473
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Set attribute based on when the user logges in?

Post by BLOMASKY »

Aware is very rich with FUNCTIONS. They are at the end of the user guide and there are quite a few handling date and time.

If you want the year try SESSIONVARS.currentYear = YEAR(CURRENT_DATE)


Bruce
PointsWell
Posts: 1460
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Set attribute based on when the user logges in?

Post by PointsWell »

lueu wrote: Fri Nov 03, 2023 2:00 pm So I've tried different combinations for current year, year, timetstamp and so on,
See https://www.awareim.com/dokuwiki/doku.php/a_f/f/10_d_t
lueu
Posts: 89
Joined: Tue Mar 07, 2023 11:49 pm

Re: Set attribute based on when the user logges in?

Post by lueu »

Thanks, I did look at the functions, I just can't find examples that shows how to set the Initial value to CURRENT_YEAR
Post Reply