The CreatorCon Call for Content is officially open! Get started here.

Populate the watch list field based on the record producer variable

LaraReddy
Tera Guru

Hi All,
Can anyone please help us on the below requirement.

We have a Record producer with set of of variables.

One of the variable option is YES , then we need to populate one specific group members on watch list field level.

Advance thanks.

2 ACCEPTED SOLUTIONS

@LaraReddy Instead of putting the hard coded sys_ids of users, you can query the sys_user_grmemeber table inside the record producer script and populate the watchlist as follows.

 
if(producer.<variable_name>=='YES'){ //Replace <variable_name> with the name of the variable you wish to check

var groupMember = new GlideRecord('sys_user_grmember');
groupMember.addQuery('group','c38f00f4530360100999ddeeff7b1298'); //Replace with the sys_id of your group
groupMember.query();
var grMemberArray = [];
while(groupMember.next()){
    grMemberArray.push(groupMember.getValue('user'));
}
current.watch_list = grMemberArray.toString();
}

Please mark the answer helpful and correct if this addresses your question.

View solution in original post

LaraReddy
Tera Guru
Thanks for the support @Sandeep Rajput .

Below script working fine for us.


if (producer.var_name == 'Yes') {
    var groupSysID = 'group_sys_id'
    var groupMembers = [];
    var gr = new GlideRecord('sys_user_grmember');  
    gr.addQuery('group', groupSysID);
    gr.addEncodedQuery('user.active=true'); 
    gr.query();
 
    while (gr.next()) {
        groupMembers.push(gr.user.toString());
    }
 
    current.watch_list = groupMembers.join(',');
}

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@LaraReddy In the record producer script field you can check the following.

 

if(producer.<variable_name>=='YES'){ //Replace <variable_name> with the name of the variable you wish to check
current.watch_list = '9087a72283b90a10442951b8beaccccddd'; //sys_id of the member
}

Hope this helps.

Hi Sandeep,
Thanks for the response.

On the group level, we have more than five users are available, do we need to pass all the user's sys_id or is there any alternate approach to add the group users to the watch list field.

And also in future, If any new user added to the same group again we need to add the added user's sys_id on script level ???


Advance thanks.

@LaraReddy Instead of putting the hard coded sys_ids of users, you can query the sys_user_grmemeber table inside the record producer script and populate the watchlist as follows.

 
if(producer.<variable_name>=='YES'){ //Replace <variable_name> with the name of the variable you wish to check

var groupMember = new GlideRecord('sys_user_grmember');
groupMember.addQuery('group','c38f00f4530360100999ddeeff7b1298'); //Replace with the sys_id of your group
groupMember.query();
var grMemberArray = [];
while(groupMember.next()){
    grMemberArray.push(groupMember.getValue('user'));
}
current.watch_list = grMemberArray.toString();
}

Please mark the answer helpful and correct if this addresses your question.

LaraReddy
Tera Guru
Thanks for the support @Sandeep Rajput .

Below script working fine for us.


if (producer.var_name == 'Yes') {
    var groupSysID = 'group_sys_id'
    var groupMembers = [];
    var gr = new GlideRecord('sys_user_grmember');  
    gr.addQuery('group', groupSysID);
    gr.addEncodedQuery('user.active=true'); 
    gr.query();
 
    while (gr.next()) {
        groupMembers.push(gr.user.toString());
    }
 
    current.watch_list = groupMembers.join(',');
}