Trim a string field value

kali
Tera Contributor

Hi All,

There is a string field , I have to trim the string field upto 30 characters and store it another string field . Please help me on this. 

4 REPLIES 4

Elijah Aromola
Mega Sage

Are you trying to limit a string to the first 30 characters?

value.substr(0, 30); 

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Try this

 

var text = "Hello world!";
var result = text.substring(0,30);

 

-Anurag

Stefan Georgiev
Tera Guru

Hello @kali ,

I am now aware of your case, but you can just set the limit of the other string field to 30 characters you just need to change the dictionary entry Max length field to 30, no scripting involved :

https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/reference-pages...

StefanGeorgiev_0-1702485345123.png

Hope that this helps you!

If the provided information answers your question, please consider marking it as Helpful and Accepting the Solution so other community users can find it faster.

All the Best,
Stefan



abirakundu23
Mega Sage

Hi @kali,

Please use below code.

var ga = " I am a girl. Hello world. Need support for rescue. is it ok for everyone? Thanks in Advance!";

var result = ga.substr(0,30);
gs.log ("trim the string field up to 30 characters:" +result);


Result:

AbiraKundu_0-1702485441972.png

Please mark helpful & accept answer if it's worthy for you.