Script to calculate the count of characters in a IM description

Hi Experts,


My requirement is to implement a scenario which will show a message when the incident description given by user is more than a particular limit. And the script should count both characters and new lines(\n). I am planning to implement this through format control. I have tried the following code under JavaScript tab of FC,  just to see length of description (action) field which user entered.

update : true

var len=record.action.length();


But it throwed error while updating an IM.

Could you please suggest a way to find the length of the description that the user have just entered in  a particular IM.


Thanks & Regards,

Sandhu Mol

  • How about CALCULATIONS tab and use lng function there.

    RAD function: lng
    A RAD function that returns the number of elements in an array or structure and the number of characters in a string. Remember to denull arrays to get the correct number of elements, but be careful when denulling arrays of structures.
    Where $variable is the array, structure, or string.
     The $variable must be an array, structure or a character string.
     Arrays return the number of elements, NULL or otherwise.
     Strings return the number of characters.
     Structures return the number of fields.
    lng("1234567890") returns 10
    lng({1,2,3}) returns 3
    lng({1,2,3,,,,}) returns 7
    lng(denull({1,2,3,,,,})) returns 3
  • If you're set on using JS you could try changing your line to this

    var len=record.action.toArray().toString().length;
  • Or use system functions.

    var len = system.functions.lng(system.functions.denull(record.action));

  • Action is an array field so in this case the system.functions.lng would return the array length rather than the character count if you don't convert it to string first.


    I tried using the RAD function to convert action to string. The length count comes out higher with that method compared to JS because it appears to be counting the curly brackets and quotes marks. Depending on the requirement that might be desirable.


    Here's the test I ran to compare

    var imRec=new SCFile("probsummary");
    var ticketNumber="IM2000943"; //replace this with your ticket number
    imRec.doSelect(new QueryCond("number",EQ,ticketNumber));
    print("JS Func Text: " imRec.action.toArray().toString());
    print("JS Func Text Length: " imRec.action.toArray().toString().length);
    print("RAD Func Text: " system.functions.denull(system.functions.str(imRec.action)));
    print("RAD Func Text Length: " system.functions.lng(system.functions.denull(system.functions.str(imRec.action)))); //includes curly brackets and quotes in the length count