Why does g_user not work on UI Page client scripts?

awright
Kilo Expert

I have been working on something to do with a UI Page and I am curious as to why the g_user commands (for example "g_user.userID") are not working in the UI Page Client Script box.

Is there any particular reason for this? I think that knowing the answer to why it works on some client scripts and not others will greatly enhance my knowledge of the platform.

9 REPLIES 9

awright
Kilo Expert

Geoff,

Try putting the g2 tag here instead. For some reason it doesn't work unless its right above the last jelly tag:



<div id="theResult"></div>
<g2:client_script type="user" />
</j:jelly>


I tried it everywhere, but It doesn't seem to work anyplace!


geoffcox
Giga Guru

The reason g_user wasn't working on my page was that the page hadn't finished rendering at the time the line of script was trying to execute. The solution is to use the jQuery ready function:

The HTML:



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- emit g_user support -->
<script>
jQuery(document).ready(function ($) {
doSomething();
});
</script>
<g2:client_script type="user" />
</j:jelly>


The Script:


function doSomething() {
alert(g_user.toString());
}


marcelo_moreli
Mega Guru

On the Client Script box in a UI Page, you can do things like:



alert("${gs.getUserID()}");


Little late but hope this helps you,


sigvalbergesen
Tera Contributor

addLoadEvent(displayUserSysId);



function displayUserSysId() {


  getActiveUser(); // this will force load the current user


  alert(g_user.userName);


}