Creating an if else statement in Record Producer where it won't select the first option, automatically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2020 04:05 PM
Hi,
I'm having an issue where I am trying to create an if-else statement in Record Producers against a multiple-choice, to be seen in an Incident ticket's short description field. Even though I select option two, it displays the variable for option 1. If I just use If statements, it's the reverse, it selectin option 3.
What am I doing wrong?
var shortDescriptionValue1 = producer.short_description.getDisplayValue() + ' issue' + ' for ' + producer.caller_id.getDisplayValue() + ', Vehicle #: ' + producer.vehicle_number;
//example: "Mobile Radio issue for John Doe, Vehicle #: 1234"
var shortDescriptionValue2 = producer.short_description.getDisplayValue() + ' issue' + ' for ' + producer.caller_id.getDisplayValue() + ', Property or Serial Number #:' + producer.property_number.getDisplayValue();
//example: "Handheld/Portable Radio issue for John Doe, Property or Serial Number #: 1234"
var shortDescriptionValue3 = producer.short_description.getDisplayValue() + ' issue' + ' for ' + producer.caller_id.getDisplayValue();
//example: "Dispatch Consoles issue for John Doe"
if(producer.short_description == 'mobile_radio');
{
current.short_description=shortDescriptionValue1;
} elseif(producer.short_description == 'handheld_portable radio');
{
current.short_description=shortDescriptionValue2;
} elseif(producer.short_description == 'dispatch_consoles');
{
current.short_description=shortDescriptionValue3;
}
- Labels:
-
Incident Management
-
Service Desk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2020 04:52 PM
Not sure if this will fix your issue, but there are a few small problems with the code you pasted.
To start, "Else If" is two words, not one. And after your "If" and "Else If" conditions, remove the semi-colons.
There may also be a consistency issue with your condition in your first "Else If" statement. Seeing the underscores in your choice list values and then that seemingly one-off space - it stands out. Might be worth checking out.
Code should look like this (note I didn't change the choice list value in your 2nd Else If condition):
var shortDescriptionValue1 = producer.short_description.getDisplayValue() + ' issue' + ' for ' + producer.caller_id.getDisplayValue() + ', Vehicle #: ' + producer.vehicle_number;
//example: "Mobile Radio issue for John Doe, Vehicle #: 1234"
var shortDescriptionValue2 = producer.short_description.getDisplayValue() + ' issue' + ' for ' + producer.caller_id.getDisplayValue() + ', Property or Serial Number #:' + producer.property_number.getDisplayValue();
//example: "Handheld/Portable Radio issue for John Doe, Property or Serial Number #: 1234"
var shortDescriptionValue3 = producer.short_description.getDisplayValue() + ' issue' + ' for ' + producer.caller_id.getDisplayValue();
//example: "Dispatch Consoles issue for John Doe"
if (producer.short_description == 'mobile_radio') {
current.short_description = shortDescriptionValue1;
} else if (producer.short_description == 'handheld_portable radio') {
current.short_description = shortDescriptionValue2;
} else if (producer.short_description == 'dispatch_consoles') {
current.short_description = shortDescriptionValue3;
}
Plug that in and try again. Like I said, not sure if it's the fix, but your code won't work until at least the "Else If" correction is made
Edit: You may want to throw in an "Else" statement after your last "Else If". It may not be required, but it's a good practice to get into in the event a value comes across that does not match your existing conditions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 10:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 11:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 02:10 PM
Thanks. I overlooked that. Still learning ServiceNow and JS.