How can I get current logged in user in servicenow ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
A manager wants a field to be mandatory only when the logged-in user belongs to a specific group. How would you implement this?
Can we achieve this via UI policy or client script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
38m ago
Hi @RadhikaG,
you can use User Presence there you can track what people do :))
And/or on the sys_user table there are fields Last login (just date) and Last login time (date and time):
No AI was used in the writing of this post. Pure #GlideFather only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4m ago
Hello @RadhikaG ,
You can achieve this using onLoad Client script, Below I had given an implementation
client script ->
function onLoad() {
var fieldName = 'field_name'; //Replace the field name you want to make mandatory
var targetGroupSysId = '3d70baa9c3e2f610bbcf1275e4013114'; //Replace your group sys_id
var ga = new GlideAjax('UserGroupCheck');
ga.addParam('sysparm_name', 'isUserInGroup');
ga.addParam('sysparm_group', targetGroupSysId);
ga.getXMLAnswer(function(answer) {
if (answer == 'true') {
g_form.setMandatory(fieldName, true);
} else {
g_form.setMandatory(fieldName, false);
}
});
}
script include ->
var UserGroupCheck = Class.create();
UserGroupCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserInGroup: function() {
var groupSysId = this.getParameter('sysparm_group');
var userSysId = gs.getUserID();
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupSysId);
gr.addQuery('user', userSysId);
gr.query();
if(gr.next()){
return true;
}else{
return false;
}
}
});
If my response was helped mark as helpful and accept the solution..
