Record producer script is not populating short description properly when using substring modifier

Danny Rhoades
Kilo Guru

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.

1 ACCEPTED SOLUTION

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;
}

View solution in original post

12 REPLIES 12

Chander Bhusha1
Tera Guru

Hi Danny,

 

In the producer script can you try by changing the script to add toString(). For example:

producer.description.toString().substring(0, 45);

It will work as i tried.

 

 

Thanks,

C B

Hi CB,

 

Thanks for the reply, but that didn't work either.  Any other ideas?

Chander Bhusha1
Tera Guru

Hi Danny,

I believe the  Its not going inside that else if part as mention below:

else if (producer.description.length > 45)

So can you try putting toString() before the length so that it will find the length of the string

as (producer.description.toString().length > 45)   and try to put log inside the else if part so to check whether its going inside or not.

If its going inside the else if then definitely it will populate the substring text.

Please let me know if it works.

Thanks,

CB

I tried that as well to no avail.  😞

I also added Nikhil's suggestion of gs.info log and it returned "description length undefined"