Update all the records on a table

robertpetrovics
Tera Contributor

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:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    //if (isLoading || newValue === '') {
        //return;
    //}
    var employmentEndDate = g_form.getValue('employment_end_date');
    if (employmentEndDate) {
        var year = parseInt(employmentEndDate.substring(6, 10));
        g_form.setValue('u_year_end_date','31-12-'+ year );
    }

}
 
 

 

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

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();
}

 

View solution in original post

7 REPLIES 7

robertpetrovics
Tera Contributor

how can I do that?

 

Jaspal Singh
Mega Patron
Mega Patron

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();
}

 

Community Alums
Not applicable

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();
}