Experiments with some built-in Map and Field functions ...

Experiments with some built-in Map and Field functions ...

In this post ... http://help.zoho.com/portal/en/community/#Topic/2266000000625224 ... user srhyne (Stephen to his friends) mentioned ...

Put all your form fields and form values into a map variable WITH 7 LINES OF CODE!

fields = getFieldNames();
form_map = map();
for each field in fields
{
 value = getFieldValue(field);
 form_map.put(field, value);
}
Being the "push the envelope" kind of guy ... my immediate thought was ... Can we reduce this to just one line of code ?

What if you could create a User Defined Function ... that could be called from any Section of any Application in your account ? ... e.g. ...

myFieldNamesValues = thisapp.GetFieldsValues();

... so I set about creating a User Defined Function like so ...
  1. fields = getFieldNames();
  2. form_map = map();
  3. for each field in fields
  4. {
  5.  value = getFieldValue(field);
  6.  form_map.put(field, value);
  7. }
  8. return form_map;
... and got some mixed results ...

a) the good news was that getFieldNames() returned the names of the fields in the Form from which the User Defined Function was being called ... I did not expect this to work ... as we were told that the User Defined Function's variable space was contained to values passed to it by the calling command via parameters.

b) the bad news was that getFieldValue(field) always returned null ... I was able to show this by invoking the same command set in an on User Input section ... as well as in a User Defined Function



I would like to see ...

1) getFieldValue(field) return the actual value in the Form's field at the time

2) even better ... have ZOHO Create provide a getFieldNameValueMap() built-in function



Gaev