- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-29-2024 12:06 AM
Hi Guys!
I need to update all the records on the ''sn_hr_core_profile'' in order to run the on load/on change client script that I created. The script autopopulates the ''u_year_end_date'' field based on "employment_end_date" field. The thing is in list view the ''u_year_end_date' field is empty unless I'm going into a record and save it( so that the on load/on change client script can run).
Can you give me a had with this?
Also, this is the client script that I'm using:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-29-2024 01:18 AM
Hi Robert,
If I understand correctly you have created a new field u_year_end_date and wish to populate the value in this field for all existing records submitted before the field was created.
If so, you need fix script or background script to update it for existing records as below.
var gr = new GlideRecord('sn_hr_core_profile');
gr.setLimit(10);//do it for 10 records.. once it works fine comment this line
gr.query();
while(gr.next()){
var valueis=parseInt((gr.employment_end_date).substring(6,10));
gr.setValue('u_year_end_date', '31-12-'+valueis);
gr.updateMultiple();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-29-2024 01:13 AM
how can I do that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-29-2024 01:18 AM
Hi Robert,
If I understand correctly you have created a new field u_year_end_date and wish to populate the value in this field for all existing records submitted before the field was created.
If so, you need fix script or background script to update it for existing records as below.
var gr = new GlideRecord('sn_hr_core_profile');
gr.setLimit(10);//do it for 10 records.. once it works fine comment this line
gr.query();
while(gr.next()){
var valueis=parseInt((gr.employment_end_date).substring(6,10));
gr.setValue('u_year_end_date', '31-12-'+valueis);
gr.updateMultiple();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-29-2024 02:32 AM
Hello @robertpetrovics,
Let me give you one solution on this,
If your client script is working as per your expectation, then you can simply run that same block of script in the BackGround script OR fix script. You just need to Glide the HR profile table.
var gr = new GlideRecord('sn_hr_core_profile');
gr.addActiveQuery();
gr.setLimit(10);
gr.query();
while(gr.next()){
var yearEnd= parseInt((gr.employment_end_date).substring(6,10));
gr.setValue('u_year_end_date', '31-12-' + yearEnd);
gr.update();
}