# Servoy Case Function

**URL:** <https://forum.servoy.com/t/servoy-case-function/9387>\
**Category:** Classic Servoy\
**Created:** [July 31, 2008, 9:41am UTC](https://forum.servoy.com/t/servoy-case-function/9387 "2008-07-31T09:41:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikos](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@Nikos](https://forum.servoy.com/u/Nikos)\
**Post date:** [July 31, 2008, 9:41am UTC](https://forum.servoy.com/t/servoy-case-function/9387/1 "2008-07-31T09:41:44Z")

</div>

Hi

Filemaker user here. How do I deploy a CASE function in Servoy?

In Filemaker I use the CASE function in a **tagwork** calculation field (indexed) or **tagwork** script:

```auto
Case(

timesheet::process="javaw.exe"; "Work";
timesheet::process="FileMaker Developer.exe"; "Work";
timesheet::process="FileMaker Pro Advanced.exe"; "Work";
timesheet::process="notepad.exe"; "Work";

timesheet::process="firefox.exe"; "Browse";
timesheet::process="iexplore.exe"; "Browse";
timesheet::process="explorer.exe"; "Browse";

timesheet::process="uTorrent.exe"; "Personal";
timesheet::process="msnmsgr.exe"; "Personal";
timesheet::process="Skype.exe"; "Personal";
timesheet::process="YahooMessenger.exe"; "Personal";

"Untagged")

```

I have two questions:

1. How do I do this in a Servoy calculation field?
2. How do I loop this in a Servoy script?

Thanks in advance.

Nikos

ps I searched the web and found an answer to use switch or var. The switch funtion didn’t work as all the results were default (“untagged”) while the var function was confusing.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 31, 2008, 9:57am UTC](https://forum.servoy.com/t/servoy-case-function/9387/2 "2008-07-31T09:57:50Z")

</div>

Hi Nikos,

I see this is your first post so welcome to the forum!

For the CASE function you do indeed need to use the SWITCH function.  
Als for always getting the default, this means you didn’t use a ‘break on case’ in your code.  
The following URL explains it.  
[http://www.developertutorials.com/learn … t-2599.php](http://www.developertutorials.com/learn-javascript/javascript-switch-statement-2599.php)

As for loops you can use a [FOR loop](http://www.webdevelopersnotes.com/tutorials/javascript/javascript_for_loop.php3) or a [WHILE loop](http://www.webdevelopersnotes.com/tutorials/javascript/javascript_while_loop.php3).  
A VAR has nothing much to do with loops other than declaring a local **var** iable to use in that loop.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Nikos](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@Nikos](https://forum.servoy.com/u/Nikos)\
**Post date:** [July 31, 2008, 11:19am UTC](https://forum.servoy.com/t/servoy-case-function/9387/3 "2008-07-31T11:19:08Z")

</div>

Hi Roclasi,

Thanks for the welcome, and link!

Got the calculation field to work with:

```auto
function tagwork()
{
	x = process;
	switch (x)
	{
	case "javaw.exe":
		return "Work";
	break;
	case "iexplore.exe":
		return "Work";
	break;
	default:
		return "Untagged";
	}
}

```

Now lets see if I can get the script to work. Thanks.

---

<div class="post-metadata">

**Author:** ![agiletortoise](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@agiletortoise](https://forum.servoy.com/u/agiletortoise)\
**Post date:** [July 31, 2008, 1:52pm UTC](https://forum.servoy.com/t/servoy-case-function/9387/4 "2008-07-31T13:52:04Z")

</div>

FYI, if you’ve got multiple cases that should execute the same code, you can group them as fallthrough cases, like this:

```auto
function tagwork() 
{ 
   x = process; 
   switch (x) 
   { 
   case "javaw.exe": 
   case "iexplore.exe": 
      return "Work"; 
   break; 
   default: 
      return "Untagged"; 
   } 
}

```

g.
