- 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 12:47 AM
Hi Danny,
It means that your length is not getting calculated that is why you are not able to get inside the else if.
So can you put three logs statement and check whether the values are coming or not
first one is
gs.log(producer.description); //Description
gs.log(producer.description.toString().length); //Description Length
gs.log(producer.description.toString());//Description in strin
Please let me know the output of the logs.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2020 01:05 AM
Those all returned as expected. The length was returned as 364 while the other two just output that description itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2020 01:13 AM
OK, I figured it out. I had to add .toString() in both places. Here's my updated script that is fully functional:
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 > 65){
current.short_description = producer.description.toString().substring(0, 65);
} else {
current.short_description = producer.description;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2020 12:26 AM
Hi Danny,
Please check if else if condition gets executed here.
You can put gs.info("description length " +producer.description.length) before the if statement and check the output in logs if its greater than 45 or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2020 12:44 AM
Hi Nikhil,
The log returned "description length undefined" as the message. The length of text is more than double 45 characters. I picked a large text block to test with. The short description get's populated but with a longer version of the text, which means it's clearly failing the length check but I'm not sure why.