Update managers of contractors in bulk

Bidhan_Singha
Tera Contributor

Hello All,

 

I have created a service catalog form where the current manager will be the requester and a new manager is selected in the form. Once approved, all the contractors' record under the old manager will be updated with the new manager via automation set in the workflow. 

The three fields which needs to be updated in the contractor's profile are - 

u_manager_ref, 
u_manager, 
u_manager_user_id
 
However, the automation is not working and the records are not getting updated. Here is the script defined in the workflow, please let me know the issue in it or if I need to add any log statement
 
(function executeRule(current, previous /*null when async*/ ) {
 
    var usris = new GlideRecord('u_contractors_onboarding');
    usris.addQuery('u_manager_ref', current.variables.current_manager);
    while (usris.next()) {

        usris.u_manager_ref = current.variables.select_a_new_manager; // Manager_MANAGER CAN UPDATE
        usris.u_manager = current.variables.select_a_new_manager.getDisplayValue();
        usris.u_manager_user_id = current.variables.select_a_new_manager.user_name; //Backend Manager
       
        usris.updateMultiple();
    }
})(current, previous);
3 REPLIES 3

Gangadhar Ravi
Giga Sage
Giga Sage

@Bidhan_Singha  you are missing usris.query(). below is updated script.

 

 

(function executeRule(current, previous /*null when async*/ ) {
 
    var usris = new GlideRecord('u_contractors_onboarding');
    usris.addQuery('u_manager_ref', current.variables.current_manager);
    usris.query();
    while (usris.next()) {

        usris.u_manager_ref = current.variables.select_a_new_manager; // Manager_MANAGER CAN UPDATE
        usris.u_manager = current.variables.select_a_new_manager.getDisplayValue();
        usris.u_manager_user_id = current.variables.select_a_new_manager.user_name; //Backend Manager
       
        usris.update();
    }
})(current, previous);

 

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

Hi Gangadhar,

My bad!! I tried again after adding usris.query(). It is still not working.

As I am not able to find other issue in the script. Can it be possible it is because of the OnChange client script I am using to populate current_manager field in the form.

Here is the client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
 
    if(newValue!=''){
    g_form.setValue('current_manager', newValue);
   }
   else{
    g_form.clearOptions();
   } 
}

Bert_c1
Kilo Patron

You don't have ursis.query() after the ursis.addQuery() line.