- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 09:19 PM
Hi All,
We have an input where we will get a value as short_description (For example lets say: 1 to 50 numbers in short_description)
I want the value which is after 1 to 30 characters.
How to trim the short_description value more than 30 characters
Regards,
Reddy
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 11:23 PM
So you need to write this in server-side script and run this accordingly.
For incident, you can do like this, which will update short description to 30 chars for all active incidents.
var gr = new GlideRecord("incident");
gr.addActiveQuery();
gr.query();
while(gr.next()) {
short_desc = gr.getValue("short_description");
gr.short_description = short_desc.substring(0,30);
gr.update();
}
mark the comment as a correct answer once worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 09:25 PM
var str = g_form.getValue('short_description');
g_form.setValue('short_description', str.substring(0, 30));
Can you try this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 09:58 PM
Hi ,
i am here getting the value from the Short description field and storing on the description fields so .where you want to store that value so you can set the field name
Write this code ::
function onSubmit() {
var sort = g_form.getValue('short_description');
var trims ='';
alert(" Short Desc length "+sort.length);
if(sort.length>=30){
var tr =sort.trim();
trims = tr.substring(0,30); // if You want after 30 char so set the (30,50) or if you want before 30 char. then set (0,30)
}
g_form.setValue('description',trims);
alert("after substract Desc. length "+g_form.getValue('description').length);
}
before Subtract:
After Subtract
If my suggestion helped then please Mark the correct & helpful.
so other community members can benefit from this information.
Thanks
Sanjay Bagri
||DxSherpa Tech. ||
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 10:42 PM
already we have some short_description data in incident more than 50 characters.
my scenario is trim existing data.
ex:-
before trim:- short_description=Service Now makes work, work better for people.
after trim:- short_description=Service Now makes work, work b (i need only 30 characters)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 10:21 PM
Hi,
var short_desc = g_form.getValue('short_description');
g_form.setValue('short_description', short_desc.substring(0,30)); // this will store the first 30 characters
if you want after 30 characters
g_form.setValue('short_description', short_desc.substring(30,short_desc.length())); // this will store the characters after 30 characters
Mark the comment as a correct answer once worked.