- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 03:32 AM
Hi Guys,
I need to populate the group names which "opened by" user belongs to on incident form. I've tried the below script but it gives me only the sys_id value, but i need the display value. Also i would like to show an alert message on the top of the form. I know it's not a good practice of using glide record in client side but help me to achieve this in any of the way.
function onLoad() {
var group_ids = [];
var user_id = g_form.getValue('opened_by')+'';
var grm_rec = new GlideRecord('sys_user_grmember');
grm_rec.addQuery('user',user_id);
grm_rec.query();
while(grm_rec.next()){
group_ids.push(grm_rec.group);
}
if(group_ids.length>0){
g_form.setValue('close_notes',group_ids+'');
}}
Regards,
Arun
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 04:14 AM
Hi,
using gliderecord is not a best practice,you have to use client script + glide ajax to retrieve all groups on client side.
I can help you on the logic on server side which you can get on the client side,
script include:
Name:getCallerGroups
var getCallerGroups = Class.create();
getCallerGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroups: function()
{
var sysid = this.getParameter('sysparm_user_name');
var grp =[];
var rec = new GlideRecord('sys_user_grmember');
rec.addQuery('user',sysid);
rec.query();
while (rec.next()) {
grp.push(rec.group.getDisplayValue().toString());
}
gs.log("munender"+grp);
return grp.toString();
},
type: 'getCallerGroups'
});
Client script:
function onLoad() {
var caller = g_form.getValue('caller_id');
var ga = new GlideAjax('getCallerGroups');
ga.addParam('sysparm_name', 'getGroups');
ga.addParam('sysparm_user_name', caller);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
Regards,
Munender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 04:46 AM
Hi Munender,
Thanks a ton. It's working fine but could please help me on how we can populate this value into a string field.
Also kindly help me on how we can get those groups one by one in the alert message.
Regards,
Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 05:04 AM
Hi,
Please specify how you want to set into the string field
second,to get them one by one
onclient side:
var ans = answer.split(',');
var ans1 = ans[0];
var ans2 = ans[1];
var ans3 = ans[2];
alert(ans1);
alert(ans2);
alert(ans3);
Regards,
Munender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 09:20 PM
Hi Munender,
Thanks for the reply again.
I want to set this value into "work notes" field one by one.
Thanks,
Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 12:23 AM
Hi Munender,
Regarding one by one alert,
If an user is part of 5+groups it will display only 3 [As per the above code]. Is there any way to display all the user group even if he is part of 50 groups one by one in a single alert. Customer don't want multiple alerts. Kindly help me on this.
Regards,
Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 11:23 PM
Hi,
Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader