- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 11:56 PM
Hi All,
I have created a Reference field in the Requested Item.(Requester Group- Reference to sys_group table).
The requirement is to show the logged in user's group in that field without adding any reference qualifier in the dictionary because this field is been used in other scripts.
Please help in this.
Thanks,
Samiksha
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 12:38 AM
Please use the following BR with the script to populate the first group upon RITM creation.
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", current.requested_for);
gr.query();
if (gr.next()) {
current.u_requester_group = gr.getValue('group'); //Change field name as per your configuration
}
})(current, previous);
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 01:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 12:38 AM
Is this a custom field? what's the use of this?
Which logged in user are you referring?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 01:21 AM
Hello @Samiksha2
You can write onLoad client script, and call the Client callable script include using GlideAjax to query the current logged-in User's group.
onLoad Client Script on Requested Item table
function onLoad() {
//Type appropriate comment here, and begin script below
var loggedinUser = g_user.userID; // It gives current logged in user sys_id
var gAjax = new GlideAjax('PopulateLoggedinUserGroup');
gAjax.addParam('sysparm_name','populateGroup');
gAjax.addParam('sysparm_user',loggedinUser);
gAjax.getXML(populateGroup);
function populateGroup(response){
var returnGroup = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('u_requester_group',returnGroup);
}
}
Client Callable Script include
var PopulateLoggedinUserGroup = Class.create();
PopulateLoggedinUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateGroup: function(){
var userId = this.getParameter('sysparm_user');
var userGroup = new GlideRecord('sys_user_grmember');
userGroup.addQuery('user',userId);
userGroup.query();
if(userGroup.next()){
return userGroup.group;
}
},
type: 'PopulateLoggedinUserGroup'
});
Please mark my answer as Helpful, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer