Add values in list type field

Rj27
Mega Guru

Hi All,

I have 'string' type field on my field. This field holds the value of groups from group table.

Now I have to push these values to a different field type 'list'. 

I am trying to pass these values from string field to server side. Glide record group table and get the sys id of all the groups passed and then add to list type. Is this feasible or any other approach?

Note: My main requirement is to add multiple values to assignment group field at same time instead of adding indivisually. Since that was not wroking i am first adding the groups in a new string type field.
find_real_file.png

1 ACCEPTED SOLUTION

try this in Before BR

(function executeRule(current, previous /*null when async*/ ) {

var groups = current.u_groups; //0f9881b02f612010501d9bacf699b67c , b6a8cd702f612010501d9bacf699b6b1

var arr = [];

var gr = new GlideRecord('sys_user_group');
gr.addQuery('nameIN'+ current.getValue("u_groups"));
gr.query();
while (gr.next()) {
       arr.push(gr.getValue("sys_id"));
}


current.u_assignment_group = arr;
gs.log('test u_assignment_group ' + current.u_assignment_group);

})(current, previous);

View solution in original post

10 REPLIES 10

Pranesh072
Mega Sage
Mega Sage

You can initialize all those values in an array and use that to update the list field.

var arr = [group0,group1,group2];

current.assignment_group=arr;

Hi Pranesh 

I tried this way but the values are not set to the assgignment group field.

I am setting this using 'After' BR and condition is when group field changes.

Can you share the BR script 

(function executeRule(current, previous /*null when async*/ ) {

var groups = current.u_groups; //0f9881b02f612010501d9bacf699b67c , b6a8cd702f612010501d9bacf699b6b1

var arr = [];

var gr = new GlideRecord('sys_user_group');
gr.addQuery('nameIN'+ current.getValue("u_groups"));
gr.query();
while (gr.next()) {
       arr.push(gr.getValue("sys_id") + "");
}

current.u_assignment_group = arr.join(',');
gs.log('test u_assignment_group ' + current.u_assignment_group);

})(current, previous);

try this in Before BR

(function executeRule(current, previous /*null when async*/ ) {

var groups = current.u_groups; //0f9881b02f612010501d9bacf699b67c , b6a8cd702f612010501d9bacf699b6b1

var arr = [];

var gr = new GlideRecord('sys_user_group');
gr.addQuery('nameIN'+ current.getValue("u_groups"));
gr.query();
while (gr.next()) {
       arr.push(gr.getValue("sys_id"));
}


current.u_assignment_group = arr;
gs.log('test u_assignment_group ' + current.u_assignment_group);

})(current, previous);