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

mdash
Giga Guru

var str = g_form.getValue('short_description');

 

g_form.setValue('short_description', str.substring(0, 30));

 

Can you try this?

Sanjay Bagri1
Tera Guru

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:

find_real_file.png

 

After Subtract

find_real_file.png

 

 


If my suggestion helped then please Mark the correct & helpful.
so other community members can benefit from this information.

Thanks
Sanjay Bagri

||DxSherpa Tech. ||

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)

 

asifnoor
Kilo Patron

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.