Trying to read string values into an array and substring each value

tomoldovan1
Giga Expert

Trying to take a string field that accepts multiple values, push into an array, and get the first 10 characters of each value and write the values back to the field.  Only getting the the first 10 characters of the entire string not the first 10 of each number in the array.

goal is to limit input to 10 characters for each string value.  This has been in place for some time as a string field (4,000) and wanted to see if I could come up with a way without changing the field type.

something like(testing with background script)

var gr = new GlideRecord('change_request');
gr.addQuery("number",'CHG00001');
gr.query();
var nbr = [];
var total = "";
while (gr.next()) {
nbr.push(gr.field_name_nbr);
  for (var i = 0; i < nbr.length; i++) {

          total +=nbr[i].substr(0,10);
           }
}


gs.print(total);

6 REPLIES 6

change below and see what you get

nbr.push(gr.field_name_nbr.toString().split(' '));

Script: undefined