- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2022 11:59 PM
Hi All
i have a typical requirement for which i need to write a script .
i have to find all incidents ( table name : incident ) where short description ( short_description) contails the word " test environment " and replace it with "dev environment" .
Please note that i dont have to replace the whole short description field , but only one particular text with another .
Can someone please help me with the script for this requirement .
Thanks a lot in advance
Regards
GARY
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 12:17 AM
Hello ,
you can try this
var inc =new GlideRecord("incident");
inc.addEncodedQuery("short_descriptionCONTAINStest environment");
inc.query();
while(inc.next())
{
if(inc.short_description.indexOf('test environment')>-1)
{
var replaced =inc.short_description.replace("test environment", "Dev environment");
inc.short_description =replaced;
inc.update();
}
}
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 12:06 AM
Hi Gary,
You can use regular expressions:
replace("old", "new"); -> this will replace only first occurrence of old to new.
Example :
(function executeRule(current, previous /*null when async*/) {
current.body = current.body.replace(/mailto:itaddress@/g, 'mailto:hraddress@');
})(current, previous);
Just replace body with "Short Description" field name for your requirement.
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 12:08 AM
Hi you can use the below script
var gr =new GlideRecord("incident");
gr.addQuery("short_description",'CONTAINS',"test environment");
gr.query();
while(gr.next())
{
gs.info(gr.number);
gr.short_description = gr.short_description.replace("test environment", "Dev environment");
gr.update();
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 12:17 AM
Hello ,
you can try this
var inc =new GlideRecord("incident");
inc.addEncodedQuery("short_descriptionCONTAINStest environment");
inc.query();
while(inc.next())
{
if(inc.short_description.indexOf('test environment')>-1)
{
var replaced =inc.short_description.replace("test environment", "Dev environment");
inc.short_description =replaced;
inc.update();
}
}
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU