The Zurich release has arrived! Interested in new features and functionalities? Click here for more

unable to get correct count in service portal

servicenow14710
Tera Expert

Hello developers,I m facing an issue getting count of a multi line text. please provide me suggestions on how to resolve this. Any help is appreciated. Thanks!

i have a multi line text where in i need to give different filenames 

var flnames = g_form.getValue('fileName');

var nameStr = flnames .replace(specialCharFilterRegExp, "");

//remove special characters- //[„",;'´`‚'"]/gi

nameStr = nameStr.replace(/^\s*$[\n\r]{1,}/gm, ""); //remove empty lines or lines only containing spaces
nameStr = nameStr.replace(/^[^\S\r\n]+|[^\S\r\n]+$/gm, ""); //remove leading and trailing spaces for each line
nameStr = nameStr.trim(); //remove leading and trailing spaces
nameStr = nameStr.toLowerCase(); //set certificate names to lower case

var namesArr = nameStr.split("\n");

nameStr = '';
for (var i = 0; i < namesArr.length; i++) {
var line = namesArr[i].replace(/\s+/g, ''); //remove spaces
if (i < (namesArr.length - 1)) { //not last line
nameStr += line + '\n';
} else { //last line
nameStr += line;
}
}

if (newValue != nameStr) {
g_form.setValue("fileName", nameStr);
}

var names1 = nameStr.split("\n");
var countString = nameStr.length;
alert(countString);

var count = names1.length || 0;
alert(count);
g_form.setValue("fileCount", count);

 

 

the count im getting is correct thorugh backend when i try it but in portal it is showing wrong count

eg: when i give file names as 

TEST1

TEST2

TEST3

TEST4

it is showing correct count in backend as 4 but 1 in service portal

1 REPLY 1

sonamsharma8789
Tera Expert

Hi,

I have tried the same code but it's giving 1 on the backend too. So here is one ask if you are providing the file name how we are finding those as filenames as the field is multiline text? I think this code is complex we don't need to write that much of it. Please explain the exact requirement