Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to copy List field value from one table to a string field of another table

Samiksha2
Mega Sage

Hi,

 

I have created a list field(BU with options a,b,c,d) in the sn_gf_goal_target table. 

and another string field(Selected BU) in the sn_gf_goal table. 

I want to copy the value of List from the Target table to Goal table.

 

Suppose Goal table has 3 Target records(1,2,3), and 

1 is selected a,b 

2 is selected c,d

3 is selected a,d.

Then in the selected BU all a,b,c,d will populate

 

Thanks!

1 ACCEPTED SOLUTION

Hi,

then update as this

var a = current.u_bu.getDisplayValue();
gs.addInfoMessage(a);
var gr = new GlideRecord('sn_gf_goal');
gr.addQuery('sys_id', current.goal);
gr.query();
if (gr.next()) {
gr.u_se_bu = gr.u_se_bu + ',' + a;
gr.update();
}

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

14 REPLIES 14

Hi Ankur,

 

before GlideRecord I missed the "new". Now Value is updating. But now problem is that it is updating whole value.

My scenario is :

Suppose Goal table has 3 Target records(1,2,3), and 

1 is selected a,b 

2 is selected c,d

3 is selected a,d.

Then in the selected BU all a,b,c,d will populate.

it should not override. If I change the value of 1 as only b and 3 as only d

then in selected bu  b,c,d should display. 

 

Hi,

then update as this

var a = current.u_bu.getDisplayValue();
gs.addInfoMessage(a);
var gr = new GlideRecord('sn_gf_goal');
gr.addQuery('sys_id', current.goal);
gr.query();
if (gr.next()) {
gr.u_se_bu = gr.u_se_bu + ',' + a;
gr.update();
}

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks Ankur.
Duplicate values are coming. How to omit that?
And also when I am removing BU value in Target form, Selected BU is not getting empty.

Hi,

get unique values

var arrayUtil = new global.ArrayUtil();
var a = current.u_bu.getDisplayValue();
gs.addInfoMessage(a);
var gr = new GlideRecord('sn_gf_goal');
gr.addQuery('sys_id', current.goal);
gr.query();
if (gr.next()) {
	var arr = gr.u_se_bu.toString().split(',');
	arr.push(a);
	arr = arrayUtil.unique(arr);
	gr.u_se_bu = arr.toString();
	gr.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Still coming duplicate value.

Samiksha2_0-1665125942067.png

Is it coming because i am selecting same value for different record?