Trim a string field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 08:07 AM - edited 12-13-2023 08:09 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 08:09 AM
Are you trying to limit a string to the first 30 characters?
value.substr(0, 30);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 08:10 AM - edited 12-13-2023 08:10 AM
Hi,
Try this
var text = "Hello world!";
var result = text.substring(0,30);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 08:35 AM
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...
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 08:38 AM
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:
Please mark helpful & accept answer if it's worthy for you.