Simple formula - for lookup

Can someone take a look at this code and tell me where I’ve messed up. I want to do a simple formula, if the supervisor is in the same department as the employee, pick the department view, if not, look at the all department view. It shows me the department view but then goes to the all view. The All view lookup works fine. Thanks for your help in advance, Cheryl

FIELD subdept :=subdept;

FIELD supervised:=supervised;

supervisor := @Prompt([OkCancelList]; “Supervisor”; “Is the supervisor in the same department?”; “Yes”; “Yes” : “No”);

@If(

supervisor = “Yes”;

choice:=@PickList([Custom] : [Single] ;varServer:varDB;“vwluSub”;“Department Lookup”;subdept; 3; subdept);

@SetField(“supervised”;choice));

supervisor = “No”;

choice2:=@PickList([Custom] : [Single] ;varServer:varDB;“vwluempname”;“Lookup”;“Select from the list”;1);

@SetField( “supervised” ; choice2 )

Subject: @Do

@Do is to do several Commands in the same if …

@If (A=B;

       @Do(

                   Thing1toDo;

                   Thing2toDo) ...

Can someone take a look at this code and tell me where I’ve messed up. I want to do a simple formula, if the supervisor is in the same department as the employee, pick the department view, if not, look at the all department view. It shows me the department view but then goes to the all view. The All view lookup works fine. Thanks for your help in advance, Cheryl

FIELD subdept :=subdept;

FIELD supervised:=supervised;

supervisor := @Prompt([OkCancelList]; “Supervisor”; “Is the supervisor in the same department?”; “Yes”; “Yes” : “No”);

@If(

supervisor = “Yes”;

choice:=@PickList([Custom] : [Single] ;varServer:varDB;“vwluSub”;“Department Lookup”;subdept; 3; subdept);

@SetField(“supervised”;choice));

supervisor = “No”;

choice2:=@PickList([Custom] : [Single] ;varServer:varDB;“vwluempname”;“Lookup”;“Select from the list”;1);

@SetField( “supervised” ; choice2 )

Subject: not quite right

Thank you for your response. I’m still getting the second prompt. I’ve checked help and the forum but I’ve played with this too long. I’m sure its simple but I’m confused. Here’s the code.

FIELD subdept :=subdept;

FIELD supervised:=supervised;

supervisor := @Prompt([OkCancelList]; “Supervisor”; “Is the supervisor in the same department?”; “Yes”; “Yes” : “No”);

@If(

supervisor = “Yes”;

@Do(

choice:=@PickList([Custom] : [Single] ;varServer:varDB;“vwluSub”;“Department Lookup”;subdept; 3; subdept);

@SetField(“supervised”;choice);

supervisor = “No”;

choice2:=@PickList([Custom] : [Single] ;varServer:varDB;“vwluempname”;“Lookup”;“Select from the list”;1);

@SetField( “supervised” ; choice2 ));

@Return(“”))

Subject: it’s a matter of structure…

You have one big @Do as the “then” clause of your @If. Everything in the @Do executes if supervisor = “Yes”. The indentation below should show what I mean.

@If(


``````@Do(

`````````choice:=@PickList([Custom] : [Single] ;varServer:varDB;"vwluSub";"Department Lookup";subdept; 3;  subdept);

`````````@SetField("supervised";choice);

`````````supervisor =  "No";

`````````choice2:=@PickList([Custom] : [Single] ;varServer:varDB;"vwluempname";"Lookup";"Select from the list";1);

`````````@SetField( "supervised" ; choice2 )

``````);

```@Return("")

)



The expression supervisor = "No" in the middle there, doesn't get treated as an error, because it's valid to have a formula statement that just returns a value (in this case the value False). A better way:



FIELD supervised :=

   @If(supervisor = "Yes";

      @PickList([Custom] : [Single] ;varServer:varDB;"vwluSub";"Department Lookup";subdept; 3;  subdept);

      @PickList([Custom] : [Single] ;varServer:varDB;"vwluempname";"Lookup";"Select from the list";1)

   );

0



@Prompt will not return a different value than "Yes" or "No" the way you're using it, so you can assume it's No if not Yes.

Subject: Fantastic

It’s working now. Thanks for the lesson Andre, much appreciated, Cheryl

Subject: There is a Version of PRompt with a yes and a no button (Result is @Yes or @No), too.