Fix script to insert record according to condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 09:40 AM - edited 04-16-2024 08:40 PM
Hi All,
I want to write a fix script to insert new records using existing values.
I have a table:- u_test
inside that there are 4 attributes: -
Patching | Start | End | Week (reference field) |
Sat 01:00 -4:00 | 14:00:00 | 18:00:00 | first week |
Fri 02:00 -5:00 | 15:00:00 | 16:00:00 | first week |
Sun 00:00 -03:00 | 15:00:00 | 20:00:00 | first week |
For weeks I have:- [week2, week3, week4] (reference value)
with each week i want to create new records with same patching, start and end .
I want to make new records with same values Just week needs to be changed to third week. So i need to insert 3 records with same start, end and patching Just need to update week field without updating the actual record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 09:50 AM
Hi @Priya75 ,
You can refer below code
var gr = new GlideRecord('u_test'); // your table name
gr.addQuery('patching', 'Sat 01:00 -4:00');
gr.query();
if(gr.next()){
gr.week = <sys_id>; // sys_id of 3rd week record if this is reference field
gr.update();
}
Please reach me out if you need anything.
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 08:31 PM
I don't want to update the record, I want to create new records with same attribute with different week.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 09:07 PM
Hi @Priya75 ,
In that case please refer below script
var gr = new GlideRecord('u_test'); // your table name
gr.initialize();
gr.patching ='Sat 01:00 -4:00';
gr.week = <sys_id>; // sys_id of 3rd week record if this is reference field
gr.insert();
Please reach me out if you need anything.
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 09:31 PM
I don't want to hardcode it ,it should go to each record and then create a new record.