How to get field labels from field list option schema

yundlu316
Kilo Guru

Our team is creating a widget that is using option schemas for Table and Fields.  We are able to use split the field list so that it appears in an array, but we want the field name and field label in an object array.

This is our code so far:

var fieldArr = [];
data.field_list = [];

if(options && options.field_list)
  fieldArr = options.field_list.split(',');

for(var i=0; i<fieldArr.length; i++){
  data.field_list.push({
    element: fieldArr[i],
    label: ?
  })
}

For Label, we've tried something like the below, but it obviously doesn't work.

label:fieldArr[i].getLabel()

Any ideas?

1 ACCEPTED SOLUTION

The Machine
Kilo Sage

Give this a try.  It looks like you can add the $sp.getField function to get the column label in your for loop.

for (i = 0; i < fieldArr.length; i++) {
	var column = $sp.getField(new GlideRecord(options.table), fieldArr[i]).label;
	data.field_list.push({
		element: fieldArr[i],
		label: column
	})
}
console.log(data.field_list);

View solution in original post

2 REPLIES 2

The Machine
Kilo Sage

Give this a try.  It looks like you can add the $sp.getField function to get the column label in your for loop.

for (i = 0; i < fieldArr.length; i++) {
	var column = $sp.getField(new GlideRecord(options.table), fieldArr[i]).label;
	data.field_list.push({
		element: fieldArr[i],
		label: column
	})
}
console.log(data.field_list);

Thanks @MB !  That worked like a charm