background script to update a description field of a record

skumar_srbh
Tera Guru

I am using below script to update the demand description field...

var gr = new GlideRecord('test_demand'); 
if (gr.get('b6a1c42cdb578c503b0cf5261d96196c')){ 
gr.setValue('long_desc', ' .... . .. . . .  ');
gr.update();
gs.print('updated!');
}
else {
gs.print('nothing updated,..');
}

in the long description, i want to put the below text in same format.

">  this is the 

description ... 
     and it should not be changed"

To get that I am using +  and \n in the end of 1st and 2nd line and + in the starting of 2nd and 3rd... but it seems to be not working. is there any easy way/function to modify it... ?  Please suggest... 

Thanks in advance....

 

 

 

1 ACCEPTED SOLUTION

Rishabh Jha
Mega Guru

Hi @skumar_srbh ,

Please try the snippet below in your background script, it should work.

 

var gr = new GlideRecord('test_demand'); 
if (gr.get('b6a1c42cdb578c503b0cf5261d96196c')){ 
gr.setValue('long_desc', "> this is the\n"+
"\n"+
"description ...\n"+
" and it should not be changed");
gr.update();
gs.info('updated!');
}
else {
gs.info('nothing updated,..');
}

 

Thanks & Regards,

Rishabh Jha

Aavenir (http://www.aavenir.com/)

View solution in original post

6 REPLIES 6

MrMuhammad
Giga Sage

I am not sure if I am understanding you correctly but I am assuming you want to update this ( ">  this is the ) in the description field. As ( " ) is escape character so to print this you will need to attach ( \ ) with it. 

Rest of the code is fine just make sure table name and fields names are correct. I tested and its working as expected.

var gr = new GlideRecord('test_demand');
if (gr.get('a9e9c33dc61122760072455df62663d2')){
  gr.setValue('description', '\"> this is update');
  gr.update();
  gs.print('updated!');
}
else {
   gs.print('nothing updated,..');
}

 

Please mark this ACCEPTED & HELPFUL if it answered your question.

Thanks & Regards,
Sharjeel

Regards,
Muhammad

Hi Sharjeel,

Thanks.....

">  this is the 

description ... 
     and it should not be changed."

 

above text in exactly same format needs to be updated in the description field.

 

I updated the code. Please cross check the table is demand or test_demand and make change to the table name accordingly, if required. 

 

var gr = new GlideRecord('demand'); //YOUR TABLE NAME
if (gr.get('b6a1c42cdb578c503b0cf5261d96196c')){
  gr.description = '\">  this is the '+'\n'+'description ...'+'\n'+'   and it should not be changed."';
  gr.update();
  gs.print('updated!');
}
else {
   gs.print('nothing updated,..');
}

 

Please mark this accepted & helpful if it answered your question.

Thanks & Regards,
Sharjeel

Regards,
Muhammad

Chander Bhusha1
Tera Guru

Hi skumar_srbh,

Please update the below script:

var gr = new GlideRecord('incident');
gr.get('878f10372f115010d1ea52492799b63d');
gr.description = '">  this is the '+'\n'+'description ...'+'\n'+'  and it should not be changed."';
gr.update();

 

The output would be:

find_real_file.png

Add '\n'  to place a new line.

 

Mark correct and helpful if it helps.

Thanks,

CB