- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2022 04:09 AM
We have a drop down field u_entity which have a,b,c as options
When option a is selected we need to set user field (reference ) with a hardcoded group A. manager name.
If B is selected we need to set the user field with hardcoded group B. manager name.
I know we can do that with client script , can some one help me with the script.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 02:23 PM
Hey man,
do you need to set the behavior in the backend or portal?
The best option in this case for me would be:
1. Define the groups in system property (in case you need to change the logic in the future, you don't need to touch the script, just change the property value),
2. Create Display business rule, it runs when the record is being displayed and you can use the server side. I would check read the sysIDs of the groups from the property and do GlideRecord to group table to read the manager and save it to scratchpad (so you would have 3 scratchpads, or better an array or object of managers)
3. Create the onChange client script and use the value from scratchpad based on your u_entity selection.
The solution would be, e.g.
1. Define new property, e.g. my_groups in [sys_properties] table, add there 3 sysIDs of the groups you need to work with, separate by comma
sysIDa,sysIDb,sysIDc
2. The business rule would be something like this:
var myGroups = gs.getProperty('my_groups');
var myGroupsArr = myGroups.split(',');
var myManagersArr = [];
for (var i=0; i<myGroupsArr.length; i++) {
var groupGR = new GlideRecord('sys_user_group');
groupGR.get(myGroupsArr[i]);
myManagersArr.push(groupGR.getValue('manager'));
{
g_scratchpad.myManagers = myManagersArr;
3. The client script would be something like this:
var myManagersArr = g_scratchpad.myManagers;
var entity = g_form.getValue('u_entity');
var managerID = '';
if(entity == 'a') {
managerID = myManagersArr [0];
}
else if (entity == 'b') {
managerID = myManagersArr [1];
}
else {
managerID = myManagersArr [2];
}
g_form.setValue('yourmanagerfield', managerID);
}
I haven't tested just wrote it from top of my head but that would be the principle.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 12:10 PM
Hello,
Yes it will work I have already tried the above code on my instance of course with my fieldname and option values and it worked perfectly fine.
Just check if all the option values and field name that you have substituted are correct in the script your are trying

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 02:01 PM
@Saurav11 please do not recommend using GlideRecords on client scripts, in this case the session is blocked until the browser gets response from server, may be not noticeable on PDI definitely has impact on production instances
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 02:05 PM
Hello Jan Cernocky can you please help me with the script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2022 02:23 PM
Hey man,
do you need to set the behavior in the backend or portal?
The best option in this case for me would be:
1. Define the groups in system property (in case you need to change the logic in the future, you don't need to touch the script, just change the property value),
2. Create Display business rule, it runs when the record is being displayed and you can use the server side. I would check read the sysIDs of the groups from the property and do GlideRecord to group table to read the manager and save it to scratchpad (so you would have 3 scratchpads, or better an array or object of managers)
3. Create the onChange client script and use the value from scratchpad based on your u_entity selection.
The solution would be, e.g.
1. Define new property, e.g. my_groups in [sys_properties] table, add there 3 sysIDs of the groups you need to work with, separate by comma
sysIDa,sysIDb,sysIDc
2. The business rule would be something like this:
var myGroups = gs.getProperty('my_groups');
var myGroupsArr = myGroups.split(',');
var myManagersArr = [];
for (var i=0; i<myGroupsArr.length; i++) {
var groupGR = new GlideRecord('sys_user_group');
groupGR.get(myGroupsArr[i]);
myManagersArr.push(groupGR.getValue('manager'));
{
g_scratchpad.myManagers = myManagersArr;
3. The client script would be something like this:
var myManagersArr = g_scratchpad.myManagers;
var entity = g_form.getValue('u_entity');
var managerID = '';
if(entity == 'a') {
managerID = myManagersArr [0];
}
else if (entity == 'b') {
managerID = myManagersArr [1];
}
else {
managerID = myManagersArr [2];
}
g_form.setValue('yourmanagerfield', managerID);
}
I haven't tested just wrote it from top of my head but that would be the principle.