Did not work Schedule job

matsui
Tera Contributor

I want to set 100 to u_test_emp_no on TableA, if value of employee_number_b on TableB and employee_number_a on TableA are same and test_flag is true.
Those employee_number_b and employee_number_a are sting type.
I created a Schedule job and ran it, but it did not working...

Can someone please help me?

 

 

var gr = new GlideRecord('TableA');
gr.addEncodedQuery("test_flag=true");
gr.query();
while (gr.next()) {
    var gr1 = new GlideRecord('TableB');
    gr1.addQuery('employee_number_a', gr.employee_number_b);
    gr1.query();
    if (gr1.next()) {
        gr1.setValue('u_test_emp_no', '100');
        gr1.update();
    }
}

 

 

3 REPLIES 3

Anil Lande
Kilo Patron

Hi,

Your script is looking for records in table B with query employee_number_a == employee_number_b.

Do you have records with same condition?

Also I see you are updating u_test_emp_no field.

Your query and script is not in sync, please explain your ask with example.

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

matsui
Tera Contributor

@Anil LandeI can see records with same condition.

I have fixed my script.  Is there a mistake in the script?

Hi @matsui ,

If that is the condition then your script looks good.

You may try adding logs to check which records are found in query and which records are getting updated.

Also I would suggest to use different variable name instead of using 'gr', you can use gr1, gr2 etc.

var grA = new GlideRecord('TableA');
grA.addEncodedQuery("test_flag=true");
grA.query();
while (grA.next()) {
gs.info('AAAA Updating : '+grA.employee_number_b);
    var gr1 = new GlideRecord('TableB');
    gr1.addQuery('employee_number_a', grA.employee_number_b);
    gr1.query();
    if (gr1.next()) {
        gr1.setValue('u_test_emp_no', '100');
        gr1.update();
gs.info('AAAA Updated : '+gr1.employee_number_a);
    }
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande