Getting all fields using getFields() method?

greg54
Tera Expert

Hello,

I have a table that extends the "task" table, but when using the getFields() method, it is only returning the few fields that are on the extended table (facilities), and not the fields from the extended table like I want.

i.e,

var sourceGR = new GlideRecord('facilities');
sourceGR.initialize();
var fields = sourceGR.getFields();



I noticed there is a method getRelatedTables() that I tried using, and the .size() is returning 1 value which I would expect since the facilities table only extends task. However, I am unable to get the value of the table out.

var relTables = sourceGR.getRelatedTables();
gs.log("relTables.size: " + relTables.size());
for(var t = 0; t < relTables.size(); t++) {
gs.log("Table: " + relTables[t]);
}

Any assistance anybody could provide would be deeply appreciated.

Thanks!

3 REPLIES 3

ccajohnson
Kilo Sage

It is unclear what you are attempting to do with your example. Please let us know what you are trying to accomplish, as well as what you are currently trying is so we can focus our solution accordingly.


Gabe1
ServiceNow Employee
ServiceNow Employee

Here is another way to go about this. On Calgary you can get the info you're looking for using:

var arrTable = GlideDBObjectManager.get().getTables('extended_table_here');

and then iterate using:

for (var i = 0; i < arrTable.size(); i++) {
...
}


it still may be a good idea to go over what you're trying to accomplish, just to be sure there isn't a better overall way of going about a solution.


thanks,
gabe


greg54
Tera Expert

Gabe & Christopher,

Thank you for your quick responses. Gabe, the code you provided worked. Thank you!

What I am trying to do is: In a custom module, I have a UI action to retrieve the fields of a table that is specified in the record with the UI action. I.e, the facilities table in this case. It is very similar in functionality to the "Auto map matching fields" UI action found on the transform map form.

When I was using the getFields() method, it was only bringing back 4 fields which are from the facilities table, but I wanted those plus fields from any table it extended, which would be "task" in this case. With the code that Gabe provided, I am able to get all of the children tables and get the fields from each.

If there is a better way to achieve this, please let me know. It would be nice if there was a subsequent method to getFields() that would return all of the fields from inherited tables, but this method works fine.

Again, thank you for your responses and help!