- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2020 11:33 PM
Here's the portion of the record producer script I'm having trouble with:
var gsi = producer.gaming_system_issue;
if (gsi == 'Yes') {
current.category = 'gaming';
current.short_description = 'Gaming Issue: ' + producer.business_service.name;
} else if (producer.description.length > 45) {
current.short_description = producer.description.substring(0, 45);
} else {
current.short_description = producer.description;
}
The first if statement works perfectly for the category and short description. However, the next else if statement doesn't work. It never truncates the description per the substring criteria. I still end up with most of the description becoming the short description. I've tried using current.comments = producer.description.toString(); earlier in the script but that didn't work either.
Not sure what I'm doing wrong.
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2020 01:11 AM
try this:
var gsi = producer.gaming_system_issue;
var description1 = producer.description.toString();
if (gsi == 'Yes') {
current.category = 'gaming';
current.short_description = 'Gaming Issue: ' + producer.business_service.name;
} else if (description1.length > 45) {
current.short_description = description1.substring(0, 45);
} else {
current.short_description = description1;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2020 01:07 AM
Hi Danny,
Please check if you are using correct fieldname i.e. description in this case. If the fieldname is correct then try converting producer.description into string by using producer.description.toString() and then use .length to check the length of string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2020 01:11 AM
try this:
var gsi = producer.gaming_system_issue;
var description1 = producer.description.toString();
if (gsi == 'Yes') {
current.category = 'gaming';
current.short_description = 'Gaming Issue: ' + producer.business_service.name;
} else if (description1.length > 45) {
current.short_description = description1.substring(0, 45);
} else {
current.short_description = description1;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2020 01:23 AM
This worked perfectly! I like this much better than my alternative solution which is below. So I'm marking this as correct, since it's a more elegant solution.
Alternative option is by adding .toString() to both spots like this:
var gsi = producer.gaming_system_issue;
if (gsi == 'Yes') {
current.category = 'gaming';
current.short_description = 'Gaming Issue: ' + producer.business_service.name;
} else if (producer.description.toString().length > 45) {
current.short_description = producer.description.toString().substring(0, 45);
} else {
current.short_description = producer.description;
}