- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 04:57 AM
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);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 05:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 05:20 AM
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.