Get current user name in F.S in content creator
Author: tanmay_nehete
Publication Date: 9/16/2019 12:58
I tried this: #global.project.getUserService().getUser().getLoginName() but this returns "SYSTEM".
Why? What I would like to have is the current user.
I want to retrieve currently logged in user name
Tags: content creator, html_channel, site architect
-
Author: MarsDD - 9/16/2019 13:09
Hi,
I had the same requirement Aktueller FS-User über globale Systemvariable global im Contentcreator
kind regards
Marcel
0 -
Author: tanmay_nehete - 9/16/2019 13:20
but i need code for same
0 -
Author: MarsDD - 9/16/2019 13:27
Write a executable where you get the current user.
The ClientScriptContext has a method "getUser".
0 -
Author: tanmay_nehete - 9/16/2019 13:30
but unfortunately my complete code is written in HTML o/p channel.
0 -
Author: mbergmann - 9/16/2019 19:51
Hi,
getting the user during generation time is not possible as the generation is not user/session specific. For example, the generated files are cached in the preview for a while, so it is not even guaranteed that a preview generation is performed at all when a user calls a preview page.
Could you describe your use case in more detail?
Michael
0 -
Author: tanmay_nehete - 9/18/2019 6:44
Hi Michael
We require only login user name in content creator. currently we're getting only "SYSTEM" with following API.
#global.project.getUserService().getUser().getLoginName()
#global.project.getUserService().getUser().getEMail()
#global.project.getUserService().getUser().getName()
#global.project.getUserService().getUser().getLDAPSection()
Regards Tanmay0 -
Author: mbergmann - 9/18/2019 6:52
Hi Tanmay,
could you explain the purpose / scenario why and when you need the user name in CC? Maybe there is another solution than trying to use template syntax (which will not be successful).
Regards
Michael
0 -
Author: MarsDD - 9/18/2019 7:15
Hi,
write a executable like that
public final synchronized Object execute(Map<String, Object> params) {
ClientScriptContext context = params.get("context");
Map<String, String> returnMap = params.get("returnMap");
User user = context.getUser();
returnMap.put("userName", user.getLoginName());
}
This executable is callable from a FirstSpirit Script and also with WE_API.
kind regards
Marcel
0 -
Author: tanmay_nehete - 9/18/2019 7:24
HI
Could please help me where should I write this & how to call this on HTML o/p channel?0 -
Author: tanmay_nehete - 9/18/2019 7:36
Hi Michael
My requirement is when user logged into first-spirit & goto Content Creator then logged in user name should be display on HTML O/P channel.
For that we've already done the HTML coding to show the list of articles. Along with we need to show the logged in user name as well.0 -
Author: mbergmann - 9/18/2019 8:18
Hi Tanmay,
I‘m still not sure WHY you need the user name in the page itself - but as I understand it is not necessarily about GENERATING the user into the HTML source (which is not possible) but only about DISPLAYING it, correct? The latter can be achieved using JS together with an executable (Marcel‘s approach).
But before getting into details I just want to be sure that fits your use case.
Regards
Michael
0 -
Author: tanmay_nehete - 9/18/2019 8:31
Hi OK thank you for this. But is this possible to select name who has modified the article.
0 -
Author: MarsDD - 9/18/2019 8:35
hi,
yes.
User user = dataset.getEditor();
0 -
Author: tanmay_nehete - 9/18/2019 8:39
Hi How to write this in HTML section.
0 -
Author: MarsDD - 9/18/2019 8:41
Hi,
you have to write i like
$CMS_VALUE(datasetVariable.getEditor().getLoginName())$
0 -
Author: mbergmann - 9/18/2019 9:36
Hi,
ah, ok. You don't want the currently logged in user in the HTML but the one who made the last change? In this case, I usually don't recommend to use the value stored at the object (as Marcel suggests).
Reason(s): From time to time it may be necessary to automatically update/change objects, for example due to a data migration or due to an automated post processing before generation - in that case the (technically) last editor would be a system user... Also: The user may be deleted in the future...
It is generally possible to "copy" the user's login to a normal text input (only when using a client) - which is usually the way I suggest. But this will need some (minor) module implementation.
But of course, that depends on the use case which we still don't know ;-)
Regards
Michael
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
16 Kommentare