- 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 09:31 PM
you should not use glide record in client side. its better to write in script include and call it in client side.
also use group_ids.push(grm_rec.getValue('group').toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 12:19 AM
Hi Shashwat,
Thanks. I've tried the your code but it's not working.
Regards,
Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 03:09 AM
Client Script-----
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getValue('caller_id');
//alert(caller);
var ajax = new GlideAjax('caller_manager');
ajax.addParam('sysparm_name','call');
ajax.addParam('sysparm_call',caller);
ajax.getXML(demo);
function demo(response){
var ans = response.responseXML.documentElement.getAttribute('answer');
alert(ans);
}
}
Script include---
call : function(){
var arr = [];
var caller = this.getParameter('sysparm_call');
var gr = new GlideRecord('sys_user_grmember');
gr.addActiveQuery();
gr.addQuery('user',caller);
gr.query();
//gs.addInfoMessage("Row count..."+gr.getRowCount());
while(gr.next()){
//return "jfghyf";
arr.push(gr.getDisplayValue('group'));
}
return arr.toString();
},
I have checked it for caller field you just change the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2019 06:52 AM
Hi Arun,
Did it solved your issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2019 06:53 AM
Hi Arun ,
Did it solved your issue