Highlighted
Honored Contributor.
Honored Contributor.
272 views

Script for fetching limited no: of characters from incident description

Hi Experts,

 

My requirement is to create a script that I can use in html templates. Which will allow only 1400 characters from the description field of an incident.

Following is the script I have tried. But When I use this in the html template (Expression) I could see the preview as null.

 

var max = $RECORD.action.length();

var actioncopy='';

var copy='';

var total=0;

var count=0;

for ( var i=0; i< max; i++)

    if ( $RECORD.action[i] != "")

    {

     copy= $RECORD.action[i];

     var max2=$RECORD.copy.length();   

If( total +max2 >1400)  

break;

else

total=total+max2;

actioncopy=actioncopy+$RECORD.action[i];

}

}

actioncopy = actioncopy.replace(/null/g,"<br/>");  

 

action refers to the description field.

Please anyone suggest me a solution.

 

Thanks & Regards,

Sandhu Mol

0 Likes
2 Replies
Highlighted
Valued Contributor.
Valued Contributor.

Re: Script for fetching limited no: of characters from incident description

Hello, 

According with your description I suppossed that you're using JavaScript in the Expressions Tab of the HTML Templates. Searching in external resources I found this information that hope if useful to you:

https://www.mediacollege.com/internet/javascript/form/limit-characters.html

 

0 Likes
Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Re: Script for fetching limited no: of characters from incident description

I tweaked your script a little bit

 

var convertedAction = $RECORD.action.toArray();
var max = convertedAction.length;
var actioncopy=[];
var copy='';
var total=0;
var count=0;
for ( var i=0; i< max; i++)
{
	if ( $RECORD.action[i] != "")
	{
		copy= convertedAction[i];
		var max2=copy.length;   
		if( total +max2 >1400)
		{
			break;
		}
		else
			{
				total=total+max2;
				actioncopy.push(convertedAction[i]);
			}
	}
}
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.