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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 08:04 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 09:07 AM
change below and see what you get
nbr.push(gr.field_name_nbr.toString().split(' '));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 09:14 AM
Script: undefined