How to access propperties of g_form elements listed as an array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 12:09 AM
Hi,
I am creating a list with all the elements of a g_form with elements method (i need the list to iterate through all the elements of the g_form)
However, when I try to get the value of every element, (for example g_form.elements[2]) I always get 'undefined'.
I am having issues in general to acces any attribute/properties of these elements. I need to verify if the element is hidden as well
How can I get all the attributes an methods of the elements?
function onSubmit() {
alert(g_form.elements[2].isSectionVisible()); //does not work
alert(g_form.elements[2].value); // doesnot work
alert(g_form.elements[2].getValue()); // doesnot work
}
Thanks
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 03:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 03:28 AM
The format of getting a value of a field is g_form.getValue(). So you would need to call it differently. So:
g_form.getValue(g_form.element[index].getID())
Here's an example of iterating through the elements array and getting the values:
g_form.elements.forEach(function(element) {
console.log(element.fieldName, "=", g_form.getValue(element.getID()));
});
Hope this helps
EDIT: Updating script for slightly cleaner output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 04:39 PM
Hi Shahid,
Thanks for your help.
It seems to be better now, however, for some reason, the getValue method is returining empty strings for all fields even when the fields have some content on it (i am testing it with some text boxes which I add content before applying the script). I am applying the script in the "onSubmit" event. See script below:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 06:50 PM
Hi Carlos,
I have tried below code onLoad client script and it works for me, please make sure you use getDisplayValue for reference field.
function onLoad() {
var fieldslist = '';
var count = 0 ;
for(var i =0; i<=6; i++)
{
if(count > 0)
fieldslist = fieldslist +","+ g_form.getValue(g_form.elements[i].getID());
if(count == 0){
fieldslist = g_form.getValue(g_form.elements[i].getID());
count += 1 ;
}
}
alert("Field list of the incident table is : " +fieldslist );
}