- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 04:19 AM
Hi,
In a UI page, I need to check whether any user is currently logged in or not. I tried the below things to retrieve the details for checking,
1) I tried using g_form.userName in the client section of the UI Page. But i didn't get the user name.
2) I also tried in the Processing Script section by using the gs.getUserID() and tried to log the result. However here too i'm unable to see user name.
Can anyone please suggest, how should i try to retrieve current user details from a UI page?
Regards,
Kamal
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2014 01:31 PM
For future reference if you need to actually get the username of the logged in user, one way to do it is use ${gs.getUser().name} or other properties like:
${gs.getUser().name} // same as username
${gs.getUser().firstName}
${gs.getUser().lastName}
${gs.getUser().fullName}
${gs.getUserID()}
Putting this in your example you gave earlier you would replace "g_user.userName" with "${gs.getUser().name}". Make sure you include the quotes.:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
<head>
<script>
function myFunction()
{
alert('Hi');
var usr = "${gs.getUser().name}"; //remember quotes are still needed
alert('Bye ' + usr);
document.getElementById('user').innerHTML = usr;
}
</script>
</head>
<body onload="myFunction()">
<div id='user'></div>
</body>
</html>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2019 02:11 AM
hi chris,
please let me know how to get form details from UI page. i dont want to use glide dialog window. pls tell me some other option. atleast the sys_id of the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2019 02:40 AM
Hi Deepthi,
Could you give a little more background for what you're asking? This original post was simply asking for logged in user information on a UI page.
For example, did you make a form on a UI page and are asking how to retrieve the information from that custom form?
If this is the case then hopefully you used the id attribute on your input elements. If you did this then you could use document.getElementById() method or $('id_name').
If you are using the process script in the UI page then you should make sure you use g:ui_form and use the name attribute on your input elements. That way you can just use the name given to that input as the variable in the process script.
ie. if I had <input name="my_id" /> in the markup I could use my_id in the process script to get the value of that input.
But the custom form wouldn't have a sys_id to it. So without a little more information of your setup and what you're really trying to do I won't be able to give you a straight answer. Please add more information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2019 04:01 AM
Hi Chris, I am glad to see your reply. please give me some quick guidence:) has to complete by today. just small thing is pending in my work. I want incident form data in ui page. onclick of button by window.open() i am opening UI page, now i need incident data here!
Thanks in advance please suggest
please see my UI action:
function printPreviewList(sysid) {
var features = "resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=yes,location=no";
var href = "ui_page.do?sys_id=f79b1548dbb323002fd3bd51399619b4";
win = window.open(href, "Printer_friendly_format", features);
win.focus();
}
UI page:
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">
<div style="overflow-y:scroll; height:600px;">
<div id="printableArea">
<g2:evaluate jelly="true">
var reqSysid = RP.getParameterValue("sys_id");
var task = new GlideRecord('sc_task');
task.addQuery('sys_id',reqSysid);
task.query();
if(task.next()){
var number = task.number;
gs.log('@@@@@'+number);
// do something with the record here
}
</g2:evaluate>
number: "$[number]"
<g:ui_form>
number: "$[number]"
<p>
page 1
<div style="page-break-after:always">testing: ${jvar_name} </div>
page 2
</p>
</g:ui_form>
</div>
<input type="button" value="Print" onClick="printDiv('printableArea')"/>
</div>
</j:jelly>
CLIENT SCRIPT:
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2019 05:04 AM
Are you trying to get data that has already been saved to the form or are you trying to capture the data before the user has saved?
If trying to capture before the user has saved why not just print the form while on the form?
Otherwise for a UI page I would add a sysparm_ or other prefix to sys_id in the URL.
Also since you have the sys_id already instead of using a .addQuery() and .query() I would just use .get().
For example:
var reqSysID = RP.getParameterValue('sysparm_sys_id')
var task = new GlideRecord('sc_task');
task.get(reqSysID);
if(task){
var number = task.number;
var short_description = task.short_description;
}
The above can be done a little better but this is just a basic example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2019 05:07 AM
hi chris,
this is already saved form!
var reqSysID = RP.getParameterValue('sysparm_sys_id')
with this i am NOT getting sc_task sys_id...
var reqSysID = RP.getParameterValue('sys_id')
with this is am getting UI PAGE sys_id