- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 11:43 PM
I have a business rule :
Runes Before Insert & Update with no additional condition.
I have a field called eventmessage (Choice type) on the form (its referred to in the script below).
I select a dropdown value from eventmessage field and save the form.
On this uddate, I need the business to run and take appropriate action based on the value selected.
The switch statements in the script below do not execute. Looking for help..
Script:
(function executeRule(current, previous /*null when async*/) {
//gs.addInfoMessage(current.eventmessage);
switch (current.eventmessage) {
case AssignCase:
gs.addInfoMessage("server side script - AssignCase event executed");
break;
case CalculateInvoiceTotals:
gs.addInfoMessage("server side script - CalculateInvoiceTotals event executed");
break;
case Failed:
gs.addInfoMessage("server side script - Failed event executed");
break;
default:
gs.addInfoMessage("server side script - default event executed");
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 12:10 AM
That's correct, even single quotes will work when you use toString() in JavaScript, i just reproduced the issue and was going to reply but you found that. Great.
Please mark the answer correct so it will move out from unanswered list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 11:46 PM
Is eventmessage a correct field name?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 11:48 PM
Please have case values in quotes and try, like
case 'AssignCase'
case 'CalculateInvoiceTotals'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2017 11:48 PM
Hello Yogesh,
Please cross verify the event name. May be that was the issue.
ServiceNow Commnunity MVP -2018 class.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2017 12:04 AM
Thank you Shishir, Karthik, I really appreciated your help.
Meanwhile, I was browsing the community posts and a suggestion from the post below worked for me..
Re: Switch case statement in a script
Here is what worked for me --
I created a variable before the Switch Statement
var x = current.eventmessage.toString();
Used the variable x in the Switch
Switch(x):{
Because the input parameter was converted to string, I added double quotes to the Case variables as follows
case "AssignCase"
Thank you again for your help,
Regards,
Yogesh