Retrieve all Form Variables and Fields on the Client Side
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2015 02:57 PM
After some substantial digging, I discovered a way to retrieve a list of all field and variable names on the client side. I figured that since g_form has the ability to retrieve values based on names passed as parameters (g_form.getValue), the names must be stored somewhere. I'm aware that this can be accomplished by passing values from server to client-side, but this seems like something that should be doable completely from the client. I resorted to the following:
//Retrieve a list of variable names
var arrVars = [];
var handler = g_form.prefixHandlers['variables'];
var nameMap = handler.handlerObject['nameMap'];
for(var i=0; i < nameMap.length;i++) {
arrVars.push('variables.' + nameMap[i].prettyName);
//Retrieve a list of field names
var arrFields = [];
for(var i=0; i<g_form.elements.length;i++) {
arrFields.push(g_form.elements[i]['fieldName']);
}
I'm aware that this is a messy approach. I would much prefer an exposed g_form object that contained these values. My question is two-fold.
1. Is there a better way to accomplish this on the client side about which I am not aware?
2. Does anyone see this causing us problems in the future (e.g. does g_form's internal structure get modified on a regular basis, etc?)
Thanks in advance for insights!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2015 03:11 PM
Matthew,
Instead you can use a Display Business rule which will set a scratch pad variable with the information you need and you can use that in the Client Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2015 03:27 PM
While this is a good way to handle it, as I mentioned above, I am looking for a solution that does not involve passing the values from the server-side, as they already exist on the client-side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2015 09:47 AM
Hi Matthew,
g_form has a map: g_form.nameMap
This has two entries per variable: prettyName and realName.
Example usage:
for (var index = 0; index < g_form.nameMap.length; index++) {
jslog("Name Map # " + index + ": " + g_form.nameMap[index].prettyName);
}
BR Matthias
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2015 10:22 AM
That suggestion does bring back names for the variables, but does not appear to do so for fields. I see that in both of our methods, it appears to also return the variable set titles as separate entries that would need to be filtered out. Thanks for the input.