How to remove the text in short description and i have try with str.replace("text",""); it doesn't work

Mohan6
Tera Contributor

find_real_file.png

 

 

 

 

i have try below code but not working try to help to remove the text ( "Mohan :Mohan :") in the incident Table 

 

var gr = new GlideRecord("incident");
gr.query();

gs.print("number : "+gr.number);
var sd = gr.getValue("short_description");
// gs.print(sd);
while(gr.next()){
gs.print(sd.replace("Mohan :Mohan :", ""));
gs.print(gr.short_description);
}

find_real_file.png

1 ACCEPTED SOLUTION

Aaron Munoz
Tera Guru
var incidentGR = new GlideRecord("incident");
incidentGR.addEncodedQuery("short_descriptionSTARTSWITHMohan :Mohan :");
incidentGR.query();
while(incidentGR.next()){
  var description = incidentGR.getValue("short_description");
  description = description.replace("Mohan :Mohan :", "");
  incidentGR.setValue("short_description", description);
  incidentGR.update();
}

It's good that you used gr.getValue("short_description") instead of gr.short_description since there is a known bug when iterating with gliderecord. You just needed to add this inside the while loop, not ouside. All that was missing are the setValue and update functions inside the loop.

As extra modifications, it's a best practice to filter your queries in case your table is large and you only need to modify a subset of records. Also, better avoid using gr as a variable and use more meaningful names.

View solution in original post

1 REPLY 1

Aaron Munoz
Tera Guru
var incidentGR = new GlideRecord("incident");
incidentGR.addEncodedQuery("short_descriptionSTARTSWITHMohan :Mohan :");
incidentGR.query();
while(incidentGR.next()){
  var description = incidentGR.getValue("short_description");
  description = description.replace("Mohan :Mohan :", "");
  incidentGR.setValue("short_description", description);
  incidentGR.update();
}

It's good that you used gr.getValue("short_description") instead of gr.short_description since there is a known bug when iterating with gliderecord. You just needed to add this inside the while loop, not ouside. All that was missing are the setValue and update functions inside the loop.

As extra modifications, it's a best practice to filter your queries in case your table is large and you only need to modify a subset of records. Also, better avoid using gr as a variable and use more meaningful names.