How can I get the field names in a form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2016 01:36 AM
I'm trying to create a client script that will get all the names of all fields in for example the Incident table.
For example
When I go to create a new Incident the jslog will print the names of the fields.
Pseudo-ish code:
var fields = get names of fields;
for(i = 0; i < fields.length; i++) {
jslog("Field " + i + ": " + fields[i]);
}
Result:
Field 0: number
Field 1: caller_id
Field 2: location
...
The reason I'm asking is because I'm trying to create an easter egg. I will of course post an article back in the community when the easter egg is done!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2016 01:49 AM
Hi Magnus,
On the client side you can use below statement
g_form.getLabel('<field_name>');
Whereas for server side scripting you can use 'getElement' method.
Thanks,
Abhinandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2016 02:28 AM
Hi Magnus,
Create a onload client script like below :
function onLoad() {
//Type appropriate comment here, and begin script below
var fieldslist = '';
var count = 0 ;
var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name','incident'); // Write the table name for which you need field name list
fields.query();
while(fields.next()){
if(count > 0)
fieldslist = fieldslist +","+ fields.element ;
if(count == 0){
fieldslist = fields.element;
count += 1 ;
}
}
alert("Field list of the incident table is : " +fieldslist )
}
Thanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2016 06:49 AM
Thanks! That's almost it. It doesn't list the fields from the parent tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2016 07:32 AM
if you are looking for just the parent task table then you will have to list it in the query. so just adding on to what Mihir stated change:
fields.addQuery('name','incident'); // Write the table name for which you need field name list
to
fields.addEncodedQuery('name=task^ORname=incident');
this will grab both table fields.