onload get value of a field from User form to Incident form

Thummala_Murthy
Kilo Contributor

Hi Team,
Can you please help me to get value of a field from User form to Incident form on load.
ex: Caller is being populated in Incident form and i want to fetch caller's Group value to Incident form.
i tried below , but it seems like is not working

var ug = g_form.getReference('sys_user');
alert(ug.getValue('u_primary_group'));
g_form.setValue('u_originator_group', ug.getValue('u_primary_group'));

Thnx
Murthy

3 REPLIES 3

coolboy
Mega Expert

Instead of sys_user use the actual field of form which is reference to user table


Thummala_Murthy
Kilo Contributor

HI,
Thanks for your reply.
But i am writing this script on incident form and how does it refer to the field direcly on user form.

I have modified my script as below, but stilll not able to fetch teh value

var callergroup = new GlideRecord('sys_user');
//alert(g_form.getValue('name'));
//alert(g_form.getValue('caller_id'));
callergroup.addQuery('name', g_form.getValue('caller_id'));
callergroup.query();
if (callergroup.next()) {
var temp = callergroup.u_primary_group;
alert(temp);
if (null != temp){
g_form.setValue('u_originator_group', temp);
}
}

Thnx
Murthy


geoffcox
Giga Guru

So from the discussion above this appears confusing. If you are looking at the Incident Form, then there is currently no "User Form" to access. Perhaps what you mean is the user table, rather than the user form?

Another problem is that you mention the "caller's" group. But, assuming the caller is a user, users can be members of many groups. How are you determining which of the users's groups you want to reference?

Your script opens a GlideRecord for the sys_user table, but puts it in a variable called callergroup, which is suspicious.

So first I think you want to determine the sys_id of the user.
In a client script, this is done with the g_user object:



var userID = g_user.userID;


Then you want to determine which group the user is a member of. For this you need the sys_user_grmember table:


var group_member = new GlideRecord('sys_user_grmember');
group_member.addQuery('user',userID);
group_member.query(); // This will get more than one if the user is a member of more than one.
if (group_member.next()) {
g_form.setValue('u_originator_group',group_member.sys_id);
}


We still have to figure out how to know which of the user's groups you care about. Do your user's have a "primary support group" on the user record?