The CreatorCon Call for Content is officially open! Get started here.

Access user's sys_id from UI Page presented as a widget on a homepage

smicloud
Tera Guru

I have created a UI Page in which I am trying to access the logged in user's sys_id. The UI Page is presented as a widget on homepage.

When accessing the page through "UI Page" in the meny, I can access the user's sys_id. But when accessing the UI Page from the homepage it is not available.

Here is the significant part of the UI Page:

Script:

$j(function() {

        $j("#check_in_area").ready(function() {

                  alert(g_user.userID);

        });

});

I have included following row in the HTML field:

        <g2:client_script type="user" />  

Widget:

function sections() {

  return {

  "Check in counter" : { "name" : "Check In and Out Front and Back Office" }

  };

}

function render() {

  var name = renderer.getPreferences().get("name")

  var gf = new GlideForm(renderer.getGC(), name, 0);

  gf.setDirect(true);

  gf.setRenderProperties(renderer.getRenderProperties());

  return gf.getRenderedPage();

}

function getEditLink() {

      return "";

}

What is the problem? How come it works when accessing the page from UI Page in the menu but no from the UI Page as a widget on a homepage?

1 ACCEPTED SOLUTION

smicloud
Tera Guru

By adding this code to the HTML part, the userID (user's sys_id) is available on the client side when embedding the UI Page in a widget:



<script>



        var g_userID="$[gs.getUser().getID()]";



</script>



Then you can access the user's sys_id in the client script just using the variable "g_userID".


View solution in original post

3 REPLIES 3

HV1
Mega Guru

Can you post your Widget script here.



-Hardik


Thanks for getting back at me. Please find the code included below.




function sections() {


  return {


  "Check in counter" : { "name" : "Check In and Out Front and Back Office" }


  };


}



function render() {


  var name = renderer.getPreferences().get("name")


  var gf = new GlideForm(renderer.getGC(), name, 0);


  gf.setDirect(true);


  gf.setRenderProperties(renderer.getRenderProperties());


  return gf.getRenderedPage();


}



function getEditLink() {  


      return "";


}


smicloud
Tera Guru

By adding this code to the HTML part, the userID (user's sys_id) is available on the client side when embedding the UI Page in a widget:



<script>



        var g_userID="$[gs.getUser().getID()]";



</script>



Then you can access the user's sys_id in the client script just using the variable "g_userID".