- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 03:06 AM
Hi All,
On form we have one URL field and we do want to update some part and for some urls we want to update the starting part , there are more than 1000 records . what is the best approach to do this.
Thanks all.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 04:39 AM
Hi @Obito,
This could be achieved via a 'Fix Script' or 'Scripts - Background' similar to the below.
Please note this is a very basic example for guidance but gives you an idea of the 'how'.
Below is a sample script leveraging the 'replace' method.
If you have any specific examples where perhaps the string replacement is a little more complicated or where we'd need to match using a regex - let me know.
As always - test in a Non-Prod environment first using specific records before running on Prod
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
//This is an example with a URL field called 'u_url_field_demo' on the incident table. Change the field name to reflect the field name on your instance and of course al the table where the fields and records are stored. In this example we're simply updating the url field value from www.google.co.uk to www.bbc.co.uk
var incWithURL = new GlideRecord('incident'); //replace with the table name where the url field is stored
incWithURL.addQuery('u_url_field_demo', 'CONTAINS', 'google'); //change the field name accordily for your instance
incWithURL.query();
while(incWithURL.next()){
gs.print('Inc number: ' + incWithURL.number + ' url before: ' + incWithURL.u_url_field_demo); //simple print statement to demonstrate
var textToReplace = incWithURL.u_url_field_demo;
var replacedText = textToReplace.replace("google", "bbc"); //update to replace what you require
incWithURL.u_url_field_demo = replacedText;
incWithURL.update();
gs.print('Inc number: ' + incWithURL.number + ' url after: ' + incWithURL.u_url_field_demo); /simple print statement to demonstrate
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 04:34 AM
Hi @Obito ,
In this case you can write a fix script to update the records based on your condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 04:39 AM
Hi @Obito,
This could be achieved via a 'Fix Script' or 'Scripts - Background' similar to the below.
Please note this is a very basic example for guidance but gives you an idea of the 'how'.
Below is a sample script leveraging the 'replace' method.
If you have any specific examples where perhaps the string replacement is a little more complicated or where we'd need to match using a regex - let me know.
As always - test in a Non-Prod environment first using specific records before running on Prod
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
//This is an example with a URL field called 'u_url_field_demo' on the incident table. Change the field name to reflect the field name on your instance and of course al the table where the fields and records are stored. In this example we're simply updating the url field value from www.google.co.uk to www.bbc.co.uk
var incWithURL = new GlideRecord('incident'); //replace with the table name where the url field is stored
incWithURL.addQuery('u_url_field_demo', 'CONTAINS', 'google'); //change the field name accordily for your instance
incWithURL.query();
while(incWithURL.next()){
gs.print('Inc number: ' + incWithURL.number + ' url before: ' + incWithURL.u_url_field_demo); //simple print statement to demonstrate
var textToReplace = incWithURL.u_url_field_demo;
var replacedText = textToReplace.replace("google", "bbc"); //update to replace what you require
incWithURL.u_url_field_demo = replacedText;
incWithURL.update();
gs.print('Inc number: ' + incWithURL.number + ' url after: ' + incWithURL.u_url_field_demo); /simple print statement to demonstrate
}