How do i add an array to a field ,separated by comma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2018 11:38 AM
Hi,
I need to add an array of values to a field separated by , comma.i m getting only one value in that but not all the values.
for example array = {1,2,3}
field A should show me 1,2,3 but it shows me only 2
if i assign the same to a variable and check in the logs , it shows me 1,2,3 .but in the field only 2.
Can anyone please advise ?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2018 06:46 AM
Try Below Code:
(function executeRule(current, previous /*null when async*/) {
var hname = [];
var tst ="";
var i;
var grhost = new GlideRecord('u_hostname');
grhost.addQuery('u_justification',current.number);
grhost.query();
while(grhost.next()){
hname.push(grhost.u_hostname.toString());
//current.u_hostname.push(grhost.u_hostname.toString());
}
for( i=0; i<hname.length; i++){
tst = tst +hname[i] + ",";
}
gs.log('tst :'+tst);
current.u_hostname = hname.join(',');
gs.log('hname :'+hname);
gs.log('current.hostname :'+current.u_hostname);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2018 05:08 AM
No, Its the same .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2018 11:21 PM
Try Below Code and let me know the info message values:
(function executeRule(current, previous /*null when async*/) {
var hname = [];
var value;
var grhost = new GlideRecord('u_hostname');
grhost.addQuery('u_justification',current.number);
grhost.query();
while(grhost.next()){
gs.addInfoMessage("grhost name"+grhost.u_hostname);
hname.push(grhost.u_hostname.toString()+'');
gs.addInfoMessage("hname"+hname);
value = hname.join(',');
}
gs.addInfoMessage("value "+value);
current.u_hostname =value;
gs.addInfoMessage("hostname"+u_hostname);
current.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018 01:10 AM
but.. why use .join(',') when hname is already an array. .join() is used to convert a string into an array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2018 08:10 AM
Hi,
Did you solve this problem? I am having similar issue?
Thanks,
Debashree