I'm trying to set a due date using business days based on date received plus a given number of days depending on what a particular test may be but am unsure how to use the while loop within an if/else if/else. All attempts have resulted in Crystal showing an error that everything after the initial if is not part of the formula. Main structure of the code comes from https://kenhamady.com/formulas/form17.shtml.
WhileReadingRecords;
DateVar Array Holidays;
DateVar Target:=Date({DATE_RECEIVED});
NumberVar Add;
NumberVar Added := 0;
if {METADATA_REPOSITORY.FIELD_VARCHAR_16} = "Test_1" then
NumberVar Add = 28;
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target
else if {ORDTASK.TESTGROUPNAME} = "Test_2" then
NumberVar Add =14;
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target
//else
NumberVar Add = DateAdd("d", Tonumber({TESTS.DURATION}), {CENTRALRECEIVING.DATE_RECEIVED});
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target
Try this:
WhileReadingRecords;
DateVar Array Holidays;
DateVar Target:=Date({DATE_RECEIVED});
NumberVar Add;
NumberVar Added := 0;
if {METADATA_REPOSITORY.FIELD_VARCHAR_16} = "Test_1" then
NumberVar Add := 28;
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target;
//else
if {ORDTASK.TESTGROUPNAME} = "Test_2" then
NumberVar Add :=14;
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target;
//else
NumberVar Add := DateAdd("d", Tonumber({TESTS.DURATION}), {CENTRALRECEIVING.DATE_RECEIVED});
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target