how to cut / trim the value short_description records

JMR2
Mega Expert

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

1 ACCEPTED SOLUTION

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.

View solution in original post

8 REPLIES 8

already we have some data in short_description  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)

This line gives you only 30 characters

g_form.setValue('short_description', short_desc.substring(0,30)); // this will store the first 30 characters

Thanks Asifnoor.

i have tried Ur code it's working fine.

it's working record by record means ( single record only ). but i want to trim all records at a time.

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.