get Field Type in Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2016 05:17 AM
Dear All,
Can someone provide an insight of how we can get the field Type for the fields in a Client Script?
something similar to the below code we use in Server side scripting.
var glideElement = current.getElement(fieldName);
var descriptor = glideElement.getED();
var internalType = descriptor.getInternalType();
Any pointers would be very helpful.
Many Thanks,
Rachana
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2016 05:59 AM
Since you already have the code server-side, the best thing would be to have a GlideAjax call and feed it the appropriate parameters to get back what you need. If you are unfamiliar with GlideAjax, here is a wiki article:
Since you get the element from current, you probably need to get the current record object. There are two methods that you can use client side to get both the table name g_form.getTableName() and the sys_id of the record g_form.getUniqueValue. For information on these methods, see the following wiki article:
GlideForm (g form) - ServiceNow Wiki
How I am envisioning this happening is that on your client script you get the table name and the sys_id of the record. Then make an Ajax call and pass the table name, the field name and the sys_id. Within the script include you take the table and the sys_id and get the record in question.
getFieldType: function() {
var tName = this.getParameter('sysparm_tbl');
var fName = this.getParameter('sysparm_fld');
var recID = this.getParameter('sysparm_rid');
var recObj = new GlideRecord(tName);
recObj.get(recID);
var glideElement = recObj.getElement(fName);
var descriptor = glideElement.getED();
var result = descriptor.getInternalType();
return result;
},
Let us know if this is helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2016 06:39 AM
You can use something like this
alert(gel('label.incident.caller_id').outerHTML);
This will give you a handle on the object and from here you can extract the type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 09:51 AM
g_form.getGlideUIElement('description').type