Function overview
Prototype
CustomList (
Start; End; Function )
Parameters
Start
End
Function see examples please
Description
Tags:
List Interval Found Set Filter Extract Custom List
- Build any list based on all Native or Custom Functions involving a 'Number' value as a parameter, such as :
Left(), Middle(), GetValue(), GetRepetitionNumber (), GetNthRecord(), GetLayoutObjectAttribute () ...
ex : - CustomList ( 1 ; Get ( FoundCount ) ; "GetNthRecord ( FirstName ; [n] )" )
will return James¶Henry¶Susan if your foundset has 3 records.
- Build any range based on Dates, Times, TimeStamps, and obviously Numbers
ex : CustomList ( 1 ; 5 ; "GetAsDate ( StartingDate ) + [n]" )
will return a range of 5 dates starting from the specified StartingDate
The 'Function' Parameter is nothing else than a litteral calculation expression.
Therefore, CustomList allows for any filtering or parsing process based on any condition you may need.
ex : CustomList ( 10 ; 100 ; "Let ( [ Value = GetValue ( MyList ; [n] ) ] ; Case ( PatternCount ( Value ; "X" ) ; Value ))" )
will parse any value containing a "X" in the 'MyList' chain, in between the 10th and the 100th values.
----------------------------------------- more examples
The Argument "Function" can be :
Examples : with [n] to define the numeric list
- "GetNthRecord ( Field ; [n] )"
- """Name =>"" & GetNthRecord ( FieldName ; [n] ) & "" FirstName =>"" & GetNthRecord ( FirstFieldName ; [n] )""
- "[n] & ""."" & MiddleValues ( Field ; [n] ; 1 )"
- "GetAsDate ( Date ) + [n]"
- "GetLayoutObjectAttribute ( ""ObjectName"" ; ""Content"" ; 1 ; [n] )"
- "Let ( [ Value = GetValue ( MyList ; [n] ) ] ; Case ( PatternCount ( Value ; "X" ) ; Value ))"
- "Let ([ $$Var[[n]] = GetNthRecord ( Field ; [n] ) ] ; """" )" // To charge N variable
- "GetRepetition ( RepetitingField ; [n] )" [...]
All native functions including Let (), any Custom Function, including CustomList() itself can be used in a formula into the "Function" argument
------------------------- Under the hood :
Basically, CustomList() does two things :
1/ Transform your formula in litteral chain :
CustomList ( 1; 4; "GetNthRecord ( Field ; [n])")
becomes
"Let ([ CLNum = 1 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &
Let ([ CLNum = 2 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &
Let ([ CLNum = 3 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &
Let ([ CLNum = 4 ] ; GetNthRecord ( Field ; CLNum ))"
2/ Evaluates this chain.
Function code
/* Special Thanks to Ugo Di Luca - Grazie Mille for his note ®
===========================================================
// Author: Agnès Barouh - barouh.agnes@wanadoo.fr
// CustomList ( Start ; End ; Function ) v_4.5
// [please, do not used "CLNum" in your calculation with Let() ]
// Objectives and examples :
- Build any list based on all Native or Custom Functions involving a 'Number' value as a parameter, such as :
Left(), Middle(), GetValue(), GetRepetitionNumber (), GetNthRecord(), GetLayoutObjectAttribute () ...
ex : - CustomList ( 1 ; Get ( FoundCount ) ; "GetNthRecord ( FirstName ; [n] )" )
will return James¶Henry¶Susan if your foundset has 3 records.
- Build any range based on Dates, Times, TimeStamps, and obviously Numbers
ex : CustomList ( 1 ; 5 ; "GetAsDate ( StartingDate ) + [n]" )
will return a range of 5 dates starting from the specified StartingDate
The 'Function' Parameter is nothing else than a litteral calculation expression.
Therefore, CustomList allows for any filtering or parsing process based on any condition you may need.
ex : CustomList ( 10 ; 100 ; "Let ( [ Value = GetValue ( MyList ; [n] ) ] ; Case ( PatternCount ( Value ; "X" ) ; Value ))" )
will parse any value containing a "X" in the 'MyList' chain, in between the 10th and the 100th values.
See the 'Under the Hood' part at the end of the function to fully understand the process of this function
--------------------------------
/* MAJOR UPDATE */ Updated July'08
--------------------------------
CustomList is based on a totally new algorithm, and is now volontarily bridled to a maximum range of 500,000 values, where the first version was technically limited to a max of 18,700 values.
Previous version still available here : http://www.briandunning.com/cf/747
The new CustomList() is faster and still is NOT recursive.
The arguments are unchanged which makes it compatible with all your previous developments involving CustomList().
For Developper ease, the new CustomList() includes a debugging mode.
find the "*****DEBUGGING MODE*****" tag in the formula below to switch mode.
When debug is set to 1, any error will be returned with its appropriate explanatory code, else the result will be set to "?"
-------------------------------- */
// ----------- FORMULA STARTS HERE -----------
Case (
/*This function will not evaluate if Invalid parameters were passed for Start and End.*/
IsEmpty ( Start ) or IsEmpty ( End ) or End < 1 or Start < 1; "";
Let ( [
Start = GetAsNumber ( Start );
End = GetAsNumber ( End );
Diff = End - Start + 1;
/*Check for a range higher than 500,000 values. CustomList() is volontarily restrained to this limit.*/
End = Case ( Diff > 500000 or End < Start or IsEmpty ( Start ) or IsEmpty ( End ); "Error"; End );
$null = "\"\"";
/*CustomList has its own recursion model. As CustomList may be involved into the "function" argument,
each CustomList expression used is passed to a repeating variable for evaluation*/
iter = Let ( $CLExeCount = $CLExeCount + 1 ; $CLExeCount & PatternCount ( Function ; "CustomList" ) + 1 ) ;
$CLn[ iter ] = Start - 1;
Calc = Case ( Diff ≥ 1600; 169; Floor ( Diff / 10 ) + 1 );
/*Here starts the "magic" of the Substitutions and the whole mechanism.
CustomList() is set to evaluate stacks of 1,700 values at a time, which is the
current limit of FileMaker internal Evaluate function */
First = Substitute ( ( 10 ^ Calc ) - 1; 9; "__________" ) & "_________";
X = Floor ( Diff / 1700 );
$CLRemainder[ iter ] = Diff - ( X * 1700 );
/*When the "Function" argument is left empty, CustomList() will return a numeric list based on the range defined */
FunctionR = Case ( IsEmpty ( Function ); "CLNum"; Substitute ( Function; ["[n]"; "CLNum"] ; [¶ ; ""] ) );
/*Each repeating variable content is parsed in order to get our String ready for the last evaluation - Special care is made for
French users here, please substitute the "definir" below with your local translation of the "Let" function if you're not using an english
version. The use of "Let ([" is recommanded anyway */
$CLExecute[ iter ] = Case ( Left ( Substitute ( Lower ( Function ); ["definir"; "Let" ]; [" "; ""]; ["¶"; ""]); 5 ) = "Let([";
Substitute ( "Let([$CLn[" & iter & "] = $CLn[" & iter & "] + 1 ; CLNum = $CLn[" & iter & "]" & First & "|";
[ "_"; "|¶Let([$CLn[" & iter & "] = $CLn[" & iter & "] + 1 ; CLNum = $CLn[" & iter & "] "]; [ "|";";" &
Replace ( FunctionR; 1; Position ( FunctionR; "["; 1; 1 ); "" ) & "&\"#^#|#^#\"&"] );
Substitute ( "Let([$CLn[" & iter & "] = $CLn[" & iter & "] + 1 ; CLNum = $CLn[" & iter & "]" & First & "|";
[ "_"; "|¶Let([$CLn[" & iter & "] = $CLn[" & iter & "] + 1 ; CLNum = $CLn[" & iter & "] "]; [ "|";"];" & FunctionR & ")&\"#^#|#^#\"&"] ) );
/*Final compilation starts here. The reminder part above each 1,700 values is treated now. */
Final = Case ( X > 0; Substitute ( ( 10 ^ X ) - 1; 9; "Evaluate ( $CLExecute[" & iter & "] & $null ) & " ) ) &
"Evaluate( LeftValues ( $CLExecute[" & iter & "] ; $CLRemainder[" & iter & "] ) & $null ) & " & $null;
/*The Final variable can now be evaluated to get our List*/
Result = Case ( End <> "Error"; Substitute ( "#^#" & Evaluate ( Final ) & "#^#";
[ "#^#|#^#"; "¶" ]; [ "¶"; "¶#^#" ]; [ "#^#¶"; "" ]; [ "¶#^#"; "¶" ]; [ "¶#^#"; "" ]; [ "#^#"; "" ] ) ) ;
$CLExecute[ iter ] = ""
// ----------- FUNCTION RESULT BELOW -----------
];
/*CustomList returns either the valid result, or an error formatted according to the debugging mode chosen above*/
Case (
( Length ( Result ) and ( Result = Filter ( Result; "?" ))) or End = "Error";
Let ([
/*****DEBUGGING MODE*****/ // Case Debug = 1, returned error "[error_CL], Number, Name and Calculation error" ,if Debug <> 1, returned error is "?"
Debug = "1";
Write = Substitute ( Function; "[n]"; 1 ); NumError = EvaluationError ( Evaluate ( Write ) );
Error = "[" & NumError & "] " & "Unlisted error | Unknown error, check calculation or check \"Start\" and \"End\" ¶102 | Field is missing¶103 | Relationship is missing¶106 | Table is missing¶113 | Function is missing¶1204 | Number, text constant, field name or \"(\" expected¶1205 | Comment is not terminated with \"*/\"¶1206 | Text constant must end with a quotation mark¶1207 | Unbalanced parenthesis¶1208 | Operator or function missing or \"(\" not expected¶1211 | List usage is not allowed in this function¶1212 | An operator (for example, +, -, *,;) is expected here¶1215 | This parameter is an invalid Get function parameter";
Pos = ValueCount ( Left ( Error; Position ( Error; NumError & " "; 1; 1 ) ) )
];
Case ( Debug = 1; "[Error_CL] | Return error : " & GetValue ( Error; Case ( Pos = 0; 1; Pos ) ) & ¶ & TextStyleAdd ( "Calculation ( for [n] = 1 ) : "; Bold ) & Write; "?" ));
Result ))
)
// ----------- UNDER THE HOOD -----------
/* Not very much afterwards...
Basically, CustomList() does two things :
1/ Transform your formula in a litteral chain :
CustomList ( 1; 4; "GetNthRecord ( Field ; [n])")
therefore becomes
"Let ([ CLNum = 1 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &
Let ([ CLNum = 2 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &
Let ([ CLNum = 3 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &
Let ([ CLNum = 4 ] ; GetNthRecord ( Field ; CLNum ))"
2/ Evaluates this chain.
Interrested in the mechanism ?
My advice then : dissect this function by escaping the 'Result' and placing one of the numerous intermediary variables available.
Special attention should be paid to the 'First' Variable, everything starts from there !
*/
// ===================================
/*
This function is published on FileMaker Custom Functions
to check for updates and provide feedback and bug reports
please visit http://www.fmfunctions.com/fid/118
Prototype: CustomList( Start; End; Function )
Function Author: Agnès (http://www.fmfunctions.com/mid/46)
Last updated: 29 December 2008
Version: 1.7
*/
// ===================================
/* Special Thanks to Ugo Di Luca - Grazie Mille for his note ® __LITBR__===========================================================__LITBR____LITBR__// Author: Agnès Barouh - barouh.agnes@wanadoo.fr__LITBR____LITBR__// CustomList ( Start ; End ; Function ) v_4.5__LITBR__// [please, do not used "CLNum" in your calculation with Let() ]__LITBR__// Objectives and examples :__LITBR____LITBR__- Build any list based on all Native or Custom Functions involving a 'Number' value as a parameter, such as :__LITBR__Left(), Middle(), GetValue(), GetRepetitionNumber (), GetNthRecord(), GetLayoutObjectAttribute () ...__LITBR__ex : - CustomList ( 1 ; Get ( FoundCount ) ; "GetNthRecord ( FirstName ; [n] )" ) __LITBR__will return James¶Henry¶Susan if your foundset has 3 records.__LITBR____LITBR__- Build any range based on Dates, Times, TimeStamps, and obviously Numbers__LITBR__ex : CustomList ( 1 ; 5 ; "GetAsDate ( StartingDate ) + [n]" )__LITBR__will return a range of 5 dates starting from the specified StartingDate__LITBR____LITBR__The 'Function' Parameter is nothing else than a litteral calculation expression. __LITBR__Therefore, CustomList allows for any filtering or parsing process based on any condition you may need.__LITBR__ex : CustomList ( 10 ; 100 ; "Let ( [ Value = GetValue ( MyList ; [n] ) ] ; Case ( PatternCount ( Value ; "X" ) ; Value ))" )__LITBR__will parse any value containing a "X" in the 'MyList' chain, in between the 10th and the 100th values.__LITBR____LITBR__See the 'Under the Hood' part at the end of the function to fully understand the process of this function__LITBR____LITBR__--------------------------------__LITBR__/* MAJOR UPDATE */ Updated July'08__LITBR__--------------------------------__LITBR____LITBR__CustomList is based on a totally new algorithm, and is now volontarily bridled to a maximum range of 500,000 values, where the first version was technically limited to a max of 18,700 values.__LITBR__Previous version still available here : http://www.briandunning.com/cf/747__LITBR____LITBR__The new CustomList() is faster and still is NOT recursive.__LITBR__The arguments are unchanged which makes it compatible with all your previous developments involving CustomList().__LITBR____LITBR__For Developper ease, the new CustomList() includes a debugging mode.__LITBR__find the "*****DEBUGGING MODE*****" tag in the formula below to switch mode.__LITBR__When debug is set to 1, any error will be returned with its appropriate explanatory code, else the result will be set to "?"__LITBR__-------------------------------- */__LITBR____LITBR__// ----------- FORMULA STARTS HERE -----------__LITBR____LITBR__Case (__LITBR__ /*This function will not evaluate if Invalid parameters were passed for Start and End.*/__LITBR____LITBR__ IsEmpty ( Start ) or IsEmpty ( End ) or End < 1 or Start < 1; "";__LITBR__ __LITBR__ Let ( [__LITBR__ Start = GetAsNumber ( Start );__LITBR__ End = GetAsNumber ( End );__LITBR__ Diff = End - Start + 1;__LITBR____LITBR__ /*Check for a range higher than 500,000 values. CustomList() is volontarily restrained to this limit.*/__LITBR____LITBR__ End = Case ( Diff > 500000 or End < Start or IsEmpty ( Start ) or IsEmpty ( End ); "Error"; End );__LITBR__ $null = "\"\"";__LITBR____LITBR__ /*CustomList has its own recursion model. As CustomList may be involved into the "function" argument, __LITBR__ each CustomList expression used is passed to a repeating variable for evaluation*/__LITBR____LITBR__ iter = Let ( $CLExeCount = $CLExeCount + 1 ; $CLExeCount & PatternCount ( Function ; "CustomList" ) + 1 ) ;__LITBR__ $CLn[ iter ] = Start - 1;__LITBR__ Calc = Case ( Diff ≥ 1600; 169; Floor ( Diff / 10 ) + 1 );__LITBR____LITBR__ /*Here starts the "magic" of the Substitutions and the whole mechanism.__LITBR__ CustomList() is set to evaluate stacks of 1,700 values at a time, which is the __LITBR__ current limit of FileMaker internal Evaluate function */__LITBR____LITBR__ First = Substitute ( ( 10 ^ Calc ) - 1; 9; "__________" ) & "_________"; __LITBR__ X = Floor ( Diff / 1700 );__LITBR__ $CLRemainder[ iter ] = Diff - ( X * 1700 );__LITBR____LITBR__ /*When the "Function" argument is left empty, CustomList() will return a numeric list based on the range defined */__LITBR____LITBR__ FunctionR = Case ( IsEmpty ( Function ); "CLNum"; Substitute ( Function; ["[n]"; "CLNum"] ; [¶ ; ""] ) );__LITBR____LITBR__ /*Each repeating variable content is parsed in order to get our String ready for the last evaluation - Special care is made for__LITBR__ French users here, please substitute the "definir" below with your local translation of the "Let" function if you're not using an english__LITBR__ version. The use of "Let ([" is recommanded anyway */__LITBR____LITBR__ $CLExecute[ iter ] = Case ( Left ( Substitute ( Lower ( Function ); ["definir"; "Let" ]; [" "; ""]; ["¶"; ""]); 5 ) = "Let([";__LITBR__ Substitute ( "Let([$CLn[" & iter & "] = $CLn[" & iter & "] + 1 ; CLNum = $CLn[" & iter & "]" & First & "|"; __LITBR__ [ "_"; "|¶Let([$CLn[" & iter & "] = $CLn[" & iter & "] + 1 ; CLNum = $CLn[" & iter & "] "]; [ "|";";" &__LITBR__ Replace ( FunctionR; 1; Position ( FunctionR; "["; 1; 1 ); "" ) & "&\"#^#|#^#\"&"] );__LITBR__ Substitute ( "Let([$CLn[" & iter & "] = $CLn[" & iter & "] + 1 ; CLNum = $CLn[" & iter & "]" & First & "|";__LITBR__ [ "_"; "|¶Let([$CLn[" & iter & "] = $CLn[" & iter & "] + 1 ; CLNum = $CLn[" & iter & "] "]; [ "|";"];" & FunctionR & ")&\"#^#|#^#\"&"] ) );__LITBR____LITBR__ /*Final compilation starts here. The reminder part above each 1,700 values is treated now. */__LITBR__ __LITBR__ Final = Case ( X > 0; Substitute ( ( 10 ^ X ) - 1; 9; "Evaluate ( $CLExecute[" & iter & "] & $null ) & " ) ) &__LITBR__ "Evaluate( LeftValues ( $CLExecute[" & iter & "] ; $CLRemainder[" & iter & "] ) & $null ) & " & $null;__LITBR____LITBR__ /*The Final variable can now be evaluated to get our List*/__LITBR____LITBR__ Result = Case ( End <> "Error"; Substitute ( "#^#" & Evaluate ( Final ) & "#^#";__LITBR__ [ "#^#|#^#"; "¶" ]; [ "¶"; "¶#^#" ]; [ "#^#¶"; "" ]; [ "¶#^#"; "¶" ]; [ "¶#^#"; "" ]; [ "#^#"; "" ] ) ) ;__LITBR__ $CLExecute[ iter ] = "" __LITBR____LITBR__// ----------- FUNCTION RESULT BELOW -----------__LITBR__ ];__LITBR__/*CustomList returns either the valid result, or an error formatted according to the debugging mode chosen above*/__LITBR____LITBR__ Case (__LITBR__ ( Length ( Result ) and ( Result = Filter ( Result; "?" ))) or End = "Error";__LITBR__ Let ([__LITBR__ /*****DEBUGGING MODE*****/ // Case Debug = 1, returned error "[error_CL], Number, Name and Calculation error" ,if Debug <> 1, returned error is "?"__LITBR__ Debug = "1";__LITBR__ Write = Substitute ( Function; "[n]"; 1 ); NumError = EvaluationError ( Evaluate ( Write ) );__LITBR__ Error = "[" & NumError & "] " & "Unlisted error | Unknown error, check calculation or check \"Start\" and \"End\" ¶102 | Field is missing¶103 | Relationship is missing¶106 | Table is missing¶113 | Function is missing¶1204 | Number, text constant, field name or \"(\" expected¶1205 | Comment is not terminated with \"*/\"¶1206 | Text constant must end with a quotation mark¶1207 | Unbalanced parenthesis¶1208 | Operator or function missing or \"(\" not expected¶1211 | List usage is not allowed in this function¶1212 | An operator (for example, +, -, *,;) is expected here¶1215 | This parameter is an invalid Get function parameter";__LITBR__ Pos = ValueCount ( Left ( Error; Position ( Error; NumError & " "; 1; 1 ) ) )__LITBR__ ];__LITBR__ Case ( Debug = 1; "[Error_CL] | Return error : " & GetValue ( Error; Case ( Pos = 0; 1; Pos ) ) & ¶ & TextStyleAdd ( "Calculation ( for [n] = 1 ) : "; Bold ) & Write; "?" ));__LITBR__ Result ))__LITBR__)__LITBR____LITBR__// ----------- UNDER THE HOOD -----------__LITBR____LITBR__/* Not very much afterwards...__LITBR__Basically, CustomList() does two things :__LITBR__1/ Transform your formula in a litteral chain :__LITBR____LITBR__CustomList ( 1; 4; "GetNthRecord ( Field ; [n])")__LITBR__therefore becomes__LITBR__"Let ([ CLNum = 1 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &__LITBR__Let ([ CLNum = 2 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &__LITBR__Let ([ CLNum = 3 ] ; GetNthRecord ( Field ; CLNum )) & ¶ &__LITBR__Let ([ CLNum = 4 ] ; GetNthRecord ( Field ; CLNum ))"__LITBR____LITBR__2/ Evaluates this chain.__LITBR____LITBR__Interrested in the mechanism ?__LITBR__My advice then : dissect this function by escaping the 'Result' and placing one of the numerous intermediary variables available.__LITBR__Special attention should be paid to the 'First' Variable, everything starts from there !__LITBR__*/__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/118__LITBR____LITBR__ Prototype: CustomList( Start; End; Function )__LITBR__ Function Author: Agnès (http://www.fmfunctions.com/mid/46)__LITBR__ Last updated: 29 December 2008__LITBR__ Version: 1.7__LITBR____LITBR__*/__LITBR__// ===================================
Comments
09 December 2008
09 December 2008
It's not really a huge issue because it's not likely to happen in real life - the only reason I mention it is because all other item's with invalid entries seem to return a nice error result, but this one just locks FM up.
09 December 2008
And thanks for your comments ! I can put "blusch", smiley with the red cheeks !
CustomList was difficult to explain but I believe that it is indeed useful thank you especially to used it and tested !
Alex,
I put calculation in data viewer and in a field unstored and field auto-enter :
CustomList ( 1 ; 5 ; "GetAsDate ( StartingDate ) + [n]" )
and here, I don't have crash,
I have just a message [for field, with format number, container or text]
[Error_CL] | Return error : 102 | Field is missing
Calculation ( for [n] = 1 ) : GetAsDate ( StartingDate ) + 1
or result = ? [for field with other format ]
test with 8, 8.5 and 9.03 Mac Tiger
Perhaps that only the 9.01 or win ? but, it is not normal and I do not see similar here
no crashes FM for me (with this formula ;) )
(Edited by Agnès on 10/12/08 )
10 December 2008
(Edited by Genx on 10/12/08 )
10 December 2008
17 July 2009
20 July 2009
no, it is not yet ok, it is too too long to calculate, I work on it from time to time but I have not found the right calculation. one day .... ( 500 values : 25 secondes, SortArray ( ) : 2 secondes .... I have work ! )
28 August 2009
I have been trying to build two custom functions for date projection (forwards & backwards) from a start/end date. I built the first function below which works perfect, but the second function returns a whacky error which looks incorrect. The only real difference is that I reversed the direction of the parsing i.e. -[n] as opposed to the normal +[n]. The really frustrating thing is that when I build the same calculation in a table field it works.. but not as a custom function..
FUNCTION 1: date.projected.end( startDate ; numDays ; KeepWeekend ) // This one works perfect
Let([
error.handler = Case( IsEmpty( startDate ) or IsEmpty( numDays ) or numDays ≤ 0 ; True ; False ) ;
//a long list of dates including weekends
$datelist.with.weekends = CustomList ( 1 ; numDays*10 ; "GetAsDate ( startDate-1 ) + [n]" ) ;
//a long list of dates excluding weekends
datelist.without.weekends = CustomList ( 1 ; numDays*10 ; "Let ( [ Value = GetValue ( $datelist.with.weekends ; [n] ) ] ; Case (
DayOfWeek( Value ) = 2 ; Value ;
DayOfWeek( Value ) = 3 ; Value ;
DayOfWeek( Value ) = 4 ; Value ;
DayOfWeek( Value ) = 5 ; Value ;
DayOfWeek( Value ) = 6 ; Value ))"
)//end customlist
];
Case(
error.handler = True ; "" ;
KeepWeekend = 1 ; GetValue( $datelist.with.weekends ; numDays ) ;
GetValue( datelist.without.weekends ; numDays )
)//end case
)//end let
FUNCTION 2: date.projected.start( endDate ; numDays ; KeepWeekend ) //this one returns an error - but why?
Let([
error.handler = Case( IsEmpty( endDate ) or IsEmpty( numDays ) or numDays ≤ 0 ; True ; False ) ;
//a long list of dates including weekends
$datelist.plus.weekends = CustomList ( 1 ; numDays*10 ; "GetAsDate ( endDate+1 ) - [n]" ) ;
//a long list of dates excluding weekends
$datelist.without.weekends = CustomList ( 1 ; numDays*10 ; "Let ( [ Value = GetValue ( $datelist.plus.weekends ; [n] ) ] ; Case (
DayOfWeek( Value ) = 2 ; Value ;
DayOfWeek( Value ) = 3 ; Value ;
DayOfWeek( Value ) = 4 ; Value ;
DayOfWeek( Value ) = 5 ; Value ;
DayOfWeek( Value ) = 6 ; Value ))"
)//end customlist
];
Case(
error.handler = True ; "" ;
KeepWeekend = 1 ; GetValue( $datelist.plus.weekends ; numDays ) ;
GetValue( $datelist.without.weekends ; numDays )
)//end case
)//end let
As I said when I build the second function above as a field calculation it works perfect??
Apologies if this is post is silly long but I couldn't think of another way to get the info in...
29 August 2009
If I look the result in "$datelist.plus.weekends" or in "$datelist.with.weekends" I obtain :
[Error_CL] | Return error : 102 | Field is missing
Calculation ( for [n] = 1 ) : GetAsDate ( endDate + 1 ) - 1
or
[Error_CL] | Return error : 102 | Field is missing
Calculation ( for [n] = 1 ) : GetAsDate ( startDate + 1 )+ 1
it's better if you write :
$endDate = endDate ;
(...)
CustomList ( 1 ; numDays*10 ; "GetAsDate ( $endDate-1 ) - [n]" ) [ the same for starDate ]
CustomList ( 1 ; numDays*10 ; "GetAsDate ( $starDate-1 ) + [n]" )
end or startDate with $ )
perhaps you don't have this error because you have a field name "endDate" or "startDate"
you said :
"when I build the same calculation in a table field it works.. but not as a custom function"
is not the same thing, if you have a field name startDate, customList take the field (not the cf'parameter) and the calc is ok
for this raison, when I make a calc, i pass only variable in customList or complet field name : table::fieldName
say me if it's ok or not, but -[n] or + [n] is not a problem
Thanks you
Agnès
(Edited by Agnès on 29/08/09 )
29 August 2009
Thank you for the insight. I understand what's going now. I modified the cf and works perfectly now. I will bear this mind for future. Thank you very much.
.... in my opinion, CustomList() is the best function in FMWorld ... Brilliant^10^10