- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 12:29 AM
Hi,
I have a description like this for all my records :
But i want to remove from the description who is an HTML type variable all the part who start with 'Les champs suivants'.
How I can do that ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 12:24 PM
Lets say I want to remove the entire line starting with "This is Identifier" in the Description (HTML) field.
First lets see how the data looks in this field.
var gr = new GlideRecord("u_experiment");
gr.get("f9fc3b798713d11045afb8c6cebb35af");
gs.print(gr.u_description);
Output:
<p>Here is sample text</p> <p>This is Identifier - This content to be removed.</p> <p>Theme: Information</p> <p>Info: Sample Info</p>
Below code will remove the entire line
var gr = new GlideRecord("u_experiment");
gr.get("f9fc3b798713d11045afb8c6cebb35af");
var str = gr.u_description;
var start = str.indexOf("This is Identifier")-3;
var end = str.substr(start).indexOf("</p>")+4;
var temp = str.substr(start, end)
gr.u_description = str.replace(temp, '');
gr.update();
Result:
Use this to update multiple records
var gr = new GlideRecord("u_experiment");
gr.addQuery("u_description", "CONTAINS", "This is Identifier");
gr.query();
gs.print(gr.getRowCount());
var str = "", tempStr = "", start = 0, end = 0;
while(gr.next())
{
str = gr.u_description;
start = str.indexOf("This is Identifier")-3;
end = str.substr(start).indexOf("</p>")+4;
tempStr = str.substr(start, end)
gr.u_description = str.replace(tempStr, '');
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 01:19 AM
Hi @Anisse Mahtat ,
What exactly you want to remove here,
Only 'Les champs suivants'. word or all the details. Can you please provide more detail on it ?
Thanks,
Pratik Malviya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 12:24 PM
Lets say I want to remove the entire line starting with "This is Identifier" in the Description (HTML) field.
First lets see how the data looks in this field.
var gr = new GlideRecord("u_experiment");
gr.get("f9fc3b798713d11045afb8c6cebb35af");
gs.print(gr.u_description);
Output:
<p>Here is sample text</p> <p>This is Identifier - This content to be removed.</p> <p>Theme: Information</p> <p>Info: Sample Info</p>
Below code will remove the entire line
var gr = new GlideRecord("u_experiment");
gr.get("f9fc3b798713d11045afb8c6cebb35af");
var str = gr.u_description;
var start = str.indexOf("This is Identifier")-3;
var end = str.substr(start).indexOf("</p>")+4;
var temp = str.substr(start, end)
gr.u_description = str.replace(temp, '');
gr.update();
Result:
Use this to update multiple records
var gr = new GlideRecord("u_experiment");
gr.addQuery("u_description", "CONTAINS", "This is Identifier");
gr.query();
gs.print(gr.getRowCount());
var str = "", tempStr = "", start = 0, end = 0;
while(gr.next())
{
str = gr.u_description;
start = str.indexOf("This is Identifier")-3;
end = str.substr(start).indexOf("</p>")+4;
tempStr = str.substr(start, end)
gr.u_description = str.replace(tempStr, '');
gr.update();
}