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

Community Alums
Not applicable

Hi @robertpetrovics ,

If you want to update all the record of any table you can run the background script you can refer the sample script 

var gr = new GlideRecord('incident');
gr.query('active', true);
gr.query();
while(gr.next()){
	gr.setValue('field_name', 'Updated Value');
	gr.updateMultiple();
}

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Sohail Khilji
Kilo Patron
Kilo Patron

your query is not clear ! can you break down your question.

 

 


ā˜‘ļø Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

robertpetrovics
Tera Contributor

Basically I only need to update the records so that the on load client script can run and do the modifications.

You would need to create a client client script and a ajax call to update all the relevent record. 


ā˜‘ļø Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect