Change the assigned to for control execution

Shaik22
Tera Expert

Hi,

 

I have 5 controls(16-D,32-S,69-H,37-M,46-I) in that every control, manually updated controls executions are there for that control executions need to change the Assigned To field. I write script any corrections.

 

var pol = new GlideRecord('sn_audit_control_execution');
pol.addEncodedQuery('u_control=c882c78a1bebf4d01d031f09b04bcb6b^ORu_control=10c85a04db0fe014e9481b115b9619d1^ORu_control=7b0357ce1baff4d01d031f09b04bcbd2^ORu_control=3ada869adb5dcc905211204a4b96195d^ORu_control=dd9e4a95dbb01c185211204a4b9619f0^u_evidence_execution=Manual');
pol.query();
if(pol.next()){
pol.setValue('assigned_to', 'sys_id of the user');
}else if{
pol.setValue('assigned_to', 'sys_id of the user');
}else if{
pol.setValue('assigned_to', 'sys_id of the user');

}else if{
pol.setValue('assigned_to', 'sys_id of the user');
}else if{
pol.setValue('assigned_to', 'sys_id of the user');
}

pol.setWorkflow(false);
pol.autoSysFields(false);
pol.update();
}

1 REPLY 1

Srinivasulu Lag
ServiceNow Employee
ServiceNow Employee

Hi @Shaik22 , Query will return all records at once which means it uses UNION internally so if you want to update all records with same user then please use following code.
var pol = new GlideRecord('sn_audit_control_execution');
pol.addEncodedQuery('u_control=c882c78a1bebf4d01d031f09b04bcb6b^ORu_control=10c85a04db0fe014e9481b115b9619d1^ORu_control=7b0357ce1baff4d01d031f09b04bcbd2^ORu_control=3ada869adb5dcc905211204a4b96195d^ORu_control=dd9e4a95dbb01c185211204a4b9619f0^u_evidence_execution=Manual');

pol.setValue('assigned_to', 'sys_id of the user');
pol.setWorkflow(false);
pol.autoSysFields(false);
pol.updateMultiple();

Thanks,
Srini