panchristo Posted November 27, 2010 Posted November 27, 2010 Hi all! I'm facing a recursive function puzzle I can't solve and would appreciate it if anyone can help. Her it is: I have a global text field (SortBy) where I store field names in, separated by CarriageReturns. What I need to do is when I refer to the contents of this field from another table (that's why global), to be able to retrieve the contents of the named fields (stored as text in SortBy) and if more than one separate them with a slash (/). The field is used to produce a CALC field to help sort records dynamically inside a portal. So far I can only refer to a single field only, since I can't write a recursive CF that will start from the last value in SortBy -> use it as a field name to get its contents -> prefix it with a "/" and -> work it's way up to the first value. Any clues?
TheTominator Posted November 27, 2010 Posted November 27, 2010 (edited) Given a table with fields "Name" and "Nickname", you can use this function like this: FieldValuesFromList ( "Name¶Nickname" ; "" ) The custom field definition is as follows. FieldValuesFromList ( theFields ; empty ) = Case( IsEmpty(theFields); Substitute(empty; "¶"; "/"); Let( [ fieldCount = ValueCount(theFields); theField = GetValue(theFields; fieldCount); remainingFields = LeftValues(theFields; fieldCount - 1); /* Only use the first line of the field's value */ theFieldValue = GetValue(GetField(theField); 1) ]; FieldValuesFromList(remainingFields; List(empty; theFieldValue)) ) ) Note that it is grabbing the values starting from the last one in the list since you specified "a recursive CF that will start from the last value in SortBy". If you wanted the result to start with the value of the first field in the list, use the following two lines instead. theField = GetValue(theFields; 1); remainingFields = RightValues(theFields; fieldCount - 1); Edited November 28, 2010 by Guest Fixed error in the 2-line substitution for processing list items top to bottom
panchristo Posted November 28, 2010 Author Posted November 28, 2010 First of all, thanks a lot for your response. Since I'm really bad at analyzing custom functions, I think I must clarify a bit my previous post because I'm not quite sure your answer is what I'm looking for. So, here we go again: I have a table called "Prefs" which has a Global Text Field called SortBy containing sth like: Prefs::CH_SortBy ="CH::Field1¶CH::Field2¶CH::Field3" Then in another table (e.g.CH)I have a field called SortOrder that refers to the Prefs::CHSortBy contents in order to specify how its records will be sorted, by getting the contents of its own fields (CH::Field1, CH::Field2, CH::Field3)as a text string, like: GetField(Evaluate(GetFieldName(CH::Field1))) & "/" & GetField(Evaluate(GetFieldName(CH::Field2)))& "/" & GetField(Evaluate(GetFieldName(CH::Field3))) Keep in mind, the contents of Prefs::SortBy are modified by a script according to which column is clicked on the portal displaying the related records of CH Table, and thus specifying a new sort order whenever the string in the CH::SortOrder field changes. The complicate use of GetField(), Evaluate() and GetFieldName() functions is to ensure naming integrity issues in case field renaming occurs during development (am I wrong at this?). Therefore, the requested CF(recursive) will have the task of building the definition line of the CH::SortOrder field dynamically. So far I am able to achieve the task only for single-line values of Prefs::SortBy, that's why I'm asking for a CF. Is this what you have understood in my previous post? If yes, I'll try to modify your CF accordingly and maybe come back to you again. I'm also thinking of integrating an Acronym-producing CF to the resulting string in order to reduce text length and facilitate sorting - What do you think? Please feel free to comment and criticise my methodology - it will help me improve!!! Thanks a lot in advance.
comment Posted November 28, 2010 Posted November 28, 2010 Since I'm really bad at analyzing custom functions, I think I must clarify a bit my previous post because I'm not quite sure your answer is what I'm looking for. Why not try it and see? I would also suggest you look at: http://fmforums.com/forum/showtopic.php?tid/202466/
Recommended Posts
This topic is 5202 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now