Get all fields of a given type

#1

How can I get all fields of a given type?
I need the fields name to use them as header in an export to CSV file.

Export job fails with OutOfMemoryError
#2

You can use the Type#fieldTypes function to retrieve all fields defined on a type.

In JavaScript, it would look like this:

MyType.fieldTypes().map(function(fieldType) { return fieldType.name(); });

Where C3.typesys.Type#fieldTypes returns an array of C3.typesys.FieldType instances. Keep in mind that a field can be a method as well.

1 Like
#3

Thanks @matt, but how I can check if a field is a method or not? because I only want fields!

#4

Check out the documentation for C3.typesys.FieldType:
https://<environment_url>/static/jsduck/index.html#!/api/C3.typesys.FieldType

Hint: At minimum, a field type consists of a name (the field name) and a value type. You’ll have to figure out how to determine if a value type is a method.

2 Likes
#5

There is FunctionType, how I can get these instances? because I can then filter out these functions from my fields list.

#6

The solution is as described bellow

MyType.fieldTypes().filter(function(fieldType) {
  var fn = fieldType.name();
  var vt = fieldType.valueType();
  return !vt.isAnyFunction();
}).map(function(fieldType) {
  return fieldType.name();
});
Is there a programmatic way to determine the data type of a specific field?
#7

Following up on this with a twist, what if I wanted all fields on my Type that are writable?

#8

define “writable” please

#9

If I did a MyType.upsert(), the fields I am allowed to define. e.g. not stored calcs, not functions, not foreign key lookups, etc.