How to pass field name to a function that returns field value?
function getFieldValue() do
record(tableName,1).'Contact Person'
end
The above function returns the value of the "Contact Person" field. How can I change the function so it will return the value of any field, by passing the field name?
7 replies
-
@Westy... In the Java (TM) programming language.. we call this "reflection".. in other languages.. "introspection" (etc).. To the best of my knowledge, The Ninox scripting language does not offer any such feature. To accomplish your objective, it would be a function with an if / else construct.. :(
Maybe others have a different approach.
-
function getFieldValue(String : text) do
String := "'" + String + "'";
let v := record(tableName,1).String
v
endgetFieldValue("Contact Person") now returns the field name instead of the field value. How can I change the function to return the field value? This is my first attempt at writing a Ninox function.
-
Oops, apparently I posted at the same time you were writing.
-
As someone new to Ninox this makes me wonder why Ninox does not use pure Javascript. Is the version they use derived from some other version of Javascript? Knowing where their version came from might be helpful in doing Google searches to find sample functions that use their syntax.
-
@Westy, I got really frustrated with some of the language limitations of Ninox a while back and did some research on designing a programming language. That tamped down my frustration a bit. I don't know if they created their own lexer & parser or customized an existing product. Some have suggested, and I have parroted, this is based on Javascript, but as I learn more about Javascript the only similarity is that it is a programming/scripting language. How Ninox handles arrays compared to how Javascript handles arrays is a very good example of that.
Like @Mconneen said you can use if-then-else or, if you have a lot of fields, use switch-do.
-
It seems like Ninox was trying to keep things simple by creating their own scripting language and not using Javascript syntax like == and {}. I can understand trying to save users the frustration of mystaking "==" for "=", and "(" for "{". However, that is a slippery slope, because as their scripting lanquage expands it becomes less friendly for Javascript users. The nice thing about pure Javascript is that whenever you have a question you can do a Google search and instantly bring up 3 or more examples. So you get to learn things from multiple perspectives.
-
Ninox people explanation:
"Ninox is a custom user-friendly english-like language to help users digitize their business processes."
Content aside
- 5 yrs agoLast active
- 7Replies
- 2491Views